Browse Source

Mostly reimplemented main.cpp and MainWidget class

Ivan Arkhipov 5 years ago
parent
commit
6fc24ef4ba

+ 17 - 7
src/Legacy-advanced/main.cpp

@@ -3,17 +3,25 @@
 #include <QLockFile>
 #include <QDir>
 
-#include "models/lotro.h"
+#include "models/lotromanager.h"
+
+#include "widgets/browsewidget.h"
+#include "widgets/exportwidget.h"
+#include "widgets/importwidget.h"
+#include "widgets/mainwindow.h"
+#include "widgets/managewidget.h"
 
 #include <QTextCodec>
 #include <QThread>
 #include <QObject>
-
+1
 int main(int argc, char *argv[])
 {
     setlocale(LC_ALL,"Russian");
-
     QApplication a(argc, argv);
+
+    QDebug() << "Checking if there's another instance of Legacy";
+
     QLockFile lockFile(QDir::temp().absoluteFilePath("rulotro.lock"));
     if(!lockFile.tryLock(1)){
         QMessageBox msgBox;
@@ -23,9 +31,11 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    QSettings *settings = new QSettings(qApp->applicationDirPath() + "/legacy_v2.ini", QSettings::IniFormat);
-    QThread *lotro_mgr_thread = new QThread();
-    Lotro *lotro_mgr = new Lotro(settings);
-    QObject::connect(lotro_mgr_thread, &QThread::finished, lotro_mgr, &QObject::deleteLater);
+    qDebug() << "Starting main frame initialisation...";
+
+    MainWindow* main_window = new MainWindow(lotro_mgr, settings, nullptr);
+    main_window->setAttribute(Qt::WA_DeleteOnClose);
+
+    qDebug() << "Finished initialisation, starting application...";
     return a.exec();
 }

+ 33 - 26
src/Legacy-advanced/widgets/mainwindow.cpp

@@ -1,6 +1,6 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
-#include "legacyapp.h"
+#include "models/lotromanager.h"
 
 #include <QBitmap>
 #include <QPainter>
@@ -12,33 +12,39 @@
 #include <QDesktopWidget>
 #include <QtConcurrent/QtConcurrent>
 
-MainWindow::MainWindow(LegacyApp *app, QWidget *parent) :
+MainWindow::MainWindow(LotroManager* mgr, QSettings* settings, QWidget *parent) :
     QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint), app(app),
     ui(new Ui::MainWindow), menuHoverWidget(nullptr), menuHoverWidgetAnimation(nullptr)
 {
-}
 
-void MainWindow::Init() {
-    ui->setupUi(this);
+    QDebug << "Initialising Settings module";
+    QSettings *settings = new QSettings(qApp->applicationDirPath() + "/legacy_v2.ini", QSettings::IniFormat);
 
-    qDebug() << "Stage 1 beginnig: Initialising frames";
 
-    export_frame = new ExportWidget(app, this);
-    import_frame = new ImportWidget(app, this);
-    manage_frame = new ManageWidget(app, this);
-    browse_frame = new BrowseWidget(app, this);
+    QDebug << "Creating lotro manager instance & thread";
+    QThread *lotro_mgr_thread = new QThread();
+    LotroManager *lotro_mgr = new LotroManager(settings);
+    QObject::connect(lotro_mgr_thread, &QThread::finished, lotro_mgr, &QObject::deleteLater, type=Qt::QueuedConnection);
+    lotro_mgr->moveToThread(lotro_mgr_thread);
+    lotro_mgr_thread->run();
 
-    ui->content_layout->addWidget(export_frame);
-    ui->content_layout->addWidget(import_frame);
-    ui->content_layout->addWidget(manage_frame);
-    ui->content_layout->addWidget(browse_frame);
+    QDebug << "Creating widgets";
+    browse_widget = new BrowseWidget(lotro_mgr, settings, this);
+    import_widget = new ImportWidget(lotro_mgr, settings, this);
+    export_widget = new ExportWidget(lotro_mgr, settings, this);
+    manage_widget = new ManageWidget(lotro_mgr, settings, this);
 
+    ui->content_layout->addWidget(export_widget);
+    ui->content_layout->addWidget(import_widget);
+    ui->content_layout->addWidget(manage_widget);
+    ui->content_layout->addWidget(browse_widget);
 
-    hideAllContentWidgets();
-    manage_frame->show();
+    ui->centralWidget->setStyleSheet("");
 
-    qDebug() << "Stage 1 completed: Initialised frames";
+    hideAllContentWidgets();
+    manage_widget->show();
 
+    qDebug() << "Making fonts and making background";
     changeFontSizeRecursive(100, this);
 
     qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
@@ -50,10 +56,12 @@ void MainWindow::Init() {
     updateGeometry();
     repaint();
 
+    qDebug() << "Initialising background updates";
     background_update_timer.setInterval(30 * 1000);
     connect(&background_update_timer, &QTimer::timeout, this, &MainWindow::randomChangeBackground);
     background_update_timer.start();
-    ui->centralWidget->setStyleSheet("");
+
+    qDebug() << "Finighing main frame initialisation";
     show();
 }
 
@@ -69,9 +77,9 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
 {
     if (event->buttons() & Qt::LeftButton) {
         move(event->globalPos() - dragPosition);
-        app->process_window->move(event->globalPos() - dragPosition +
-                                  QPoint((width() - app->process_window->width()) / 2, (height() - app->process_window->height()) / 2)
-                                  );
+//        app->process_window->move(event->globalPos() - dragPosition +
+//                                  QPoint((width() - app->process_window->width()) / 2, (height() - app->process_window->height()) / 2)
+//                                  );
         event->accept();
     }
 }
@@ -145,25 +153,25 @@ MainWindow::~MainWindow()
 void MainWindow::on_menuentry_1_common_clicked()
 {
     hideAllContentWidgets();
-    manage_frame->show();
+    manage_widget->show();
 }
 
 void MainWindow::on_menuentry_2_common_clicked()
 {
     hideAllContentWidgets();
-    export_frame->show();
+    export_widget->show();
 }
 
 void MainWindow::on_menuentry_3_common_clicked()
 {
     hideAllContentWidgets();
-    import_frame->show();
+    import_widget->show();
 }
 
 void MainWindow::on_menuentry_4_common_clicked()
 {
     hideAllContentWidgets();
-    browse_frame->show();
+    browse_widget->show();
 }
 
 void MainWindow::onHoverMenuentry()
@@ -175,7 +183,6 @@ void MainWindow::setupWindowBackgroundAndMask()
 {
     current_bg = background->scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     current_mask = current_bg.mask();
-    current_mask.save(QApplication::applicationDirPath() + "/abacaba.png");
     setMask(current_mask);
 
     QPalette palette;

+ 10 - 9
src/Legacy-advanced/widgets/mainwindow.h

@@ -18,7 +18,7 @@ class MainWindow;
 }
 
 class MenuEntry;
-class LegacyApp;
+class LotroManager;
 
 class MainWindow : public QMainWindow
 {
@@ -28,7 +28,7 @@ class MainWindow : public QMainWindow
     };
 
 public:
-    explicit MainWindow(LegacyApp *app = 0, QWidget *parent = 0);
+    explicit MainWindow(LotroManager* mgr, QSettings* settings, QWidget *parent = 0);
     void Init();
     void changeFontSizeRecursive(size_t percent, QWidget* widget);
     ~MainWindow();
@@ -67,10 +67,16 @@ private:
     void hideAllContentWidgets();
 
 private:
-    LegacyApp *app;
-
     Ui::MainWindow *ui;
 
+    LotroManager* lotro_manager;
+    QThread *lotro_mgr_thread;
+
+    ExportWidget *export_widget;
+    ImportWidget *import_widget;
+    ManageWidget *manage_widget;
+    BrowseWidget *browse_widget;
+
     QWidget* menuHoverWidget;
     QPropertyAnimation* menuHoverWidgetAnimation;
     QPropertyAnimation* menuHoverWidgetScaleAnimation;
@@ -78,11 +84,6 @@ private:
 
     QPoint dragPosition;
 
-    ExportWidget *export_frame;
-    ImportWidget *import_frame;
-    ManageWidget *manage_frame;
-    BrowseWidget *browse_frame;
-
     QPixmap *background;
     QPixmap *next_pixmap {nullptr};