Преглед изворни кода

Fixed main, reimplemented MainWindow and fixed background fade effect, renamed processdialog to lotroprocessdialog

Ivan Arkhipov пре 5 година
родитељ
комит
3c2afc1c94

+ 3 - 3
src/Legacy-advanced/Legacy-advanced.pro

@@ -37,7 +37,7 @@ SOURCES += \
     widgets\managewidget.cpp \
     widgets\menuentry.cpp \
     widgets\messagedialog.cpp \
-    widgets\processdialog.cpp
+    widgets\lotroprocessdialog.cpp
 
 HEADERS += \
     models\downloader.h \
@@ -50,7 +50,7 @@ HEADERS += \
     widgets\managewidget.h \
     widgets\menuentry.h \
     widgets\messagedialog.h \
-    widgets\processdialog.h
+    widgets\lotroprocessdialog.h
 
 FORMS += \
     widgets\browsewidget.ui \
@@ -59,7 +59,7 @@ FORMS += \
     widgets\mainwindow.ui \
     widgets\managewidget.ui \
     widgets\messagedialog.ui \
-    widgets\processdialog.ui
+    widgets\lotroprocessdialog.ui
 
 RESOURCES += \
     resources\backgrounds.qrc \

+ 14 - 5
src/Legacy-advanced/main.cpp

@@ -12,15 +12,16 @@
 #include "widgets/managewidget.h"
 
 #include <QTextCodec>
-#include <QThread>
-#include <QObject>
-1
+#include <QDebug>
+#include <QResource>
+#include <QFontDatabase>
+
 int main(int argc, char *argv[])
 {
     setlocale(LC_ALL,"Russian");
     QApplication a(argc, argv);
 
-    QDebug() << "Checking if there's another instance of Legacy";
+    qDebug() << "Checking if there's another instance of Legacy";
 
     QLockFile lockFile(QDir::temp().absoluteFilePath("rulotro.lock"));
     if(!lockFile.tryLock(1)){
@@ -31,9 +32,17 @@ int main(int argc, char *argv[])
         return 1;
     }
 
+    qDebug() << "Registering resources";
+    QResource::registerResource(QApplication::applicationDirPath() + "/data01.gtr");
+    QResource::registerResource(QApplication::applicationDirPath() + "/data02.gtr");
+
+    QFontDatabase::addApplicationFont(":/assets/fonts/trajan.ttf");
+    QFontDatabase::addApplicationFont(":/assets/fonts/viking.ttf");
+    QFontDatabase::addApplicationFont(":/assets/fonts/title.ttf");
+
     qDebug() << "Starting main frame initialisation...";
 
-    MainWindow* main_window = new MainWindow(lotro_mgr, settings, nullptr);
+    MainWindow* main_window = new MainWindow(nullptr);
     main_window->setAttribute(Qt::WA_DeleteOnClose);
 
     qDebug() << "Finished initialisation, starting application...";

+ 114 - 0
src/Legacy-advanced/widgets/lotroprocessdialog.cpp

@@ -0,0 +1,114 @@
+#include "lotroprocessdialog.h"
+#include "ui_processdialog.h"
+#include <QPixmap>
+#include <QBitmap>
+#include <QMouseEvent>
+#include "models/lotromanager.h"
+#include <QTextCodec>
+using namespace LOTRO_DAT;
+
+LotroProcessDialog::LotroProcessDialog(LotroManager* mgr, QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::ProcessDialog), lotro_manager(mgr)
+{
+    ui->setupUi(this);
+    setModal(true);
+    setWindowTitle("Выполнение операции...");
+    QPixmap background(":/assets/backgrounds/process_dialog.png");
+
+    QPixmap current_bg = background.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+    QBitmap current_mask = current_bg.mask();
+    setMask(current_mask);
+
+    QPalette palette;
+    palette.setBrush(QPalette::Window, current_bg);
+    setPalette(palette);
+
+    loader.setFileName(":/assets/backgrounds/loading-gear.gif");
+    ui->loader->setMovie(&loader);
+    loader.setScaledSize(ui->loader->size());
+    loader.start();
+
+    uiUpdateTimer.setInterval(30);
+    connect(&uiUpdateTimer, &QTimer::timeout, this, &LotroProcessDialog::updateUI);
+    uiUpdateTimer.start();
+}
+
+void LotroProcessDialog::mousePressEvent(QMouseEvent *event)
+{
+    if (event->button() == Qt::LeftButton) {
+        dragPosition = event->globalPos() - frameGeometry().topLeft();
+        event->accept();
+    }
+}
+
+void LotroProcessDialog::updateUI()
+{
+    if (!qApp)
+        return;
+
+//    std::string debug_msg = app->client_local_dat.GetStatusModule().GetDebugMessage();
+//    QTextCodec *codec = QTextCodec::codecForName("UTF8");
+//    QByteArray ba(debug_msg.c_str());
+//    QString dmsg = codec->toUnicode(ba);
+
+//    int percentage = app->client_local_dat.GetStatusModule().GetPercentage();
+
+//    DatStatus::DAT_STATUS status = app->client_local_dat.GetStatusModule().GetStatus();
+//    QString title = "";
+
+//    switch (status) {
+//    case DatStatus::E_INITIALISING:
+//        title = "Инициализация";
+//        break;
+//    case DatStatus::E_EXTRACTING:
+//        title = "Извлечение данных";
+//        break;
+//    case DatStatus::E_PATCHING:
+//        title = "Применение патча";
+//        break;
+//    case DatStatus::E_COMMITING:
+//        title = "Фиксация данных";
+//        break;
+//    case DatStatus::E_BACKUP_CREATING:
+//        title = "Создание резервной копии";
+//        break;
+//    case DatStatus::E_BACKUP_REMOVING:
+//        title = "Удаление резервной копии";
+//        break;
+//    case DatStatus::E_GATHERING_INFO:
+//        title = "Сбор информации ядра";
+//        break;
+//    case DatStatus::E_FREE:
+//        title = "Свободен";
+//        break;
+//    default:
+//        title = "Неизвестная операция";
+//        break;
+//    }
+
+//    if (status == DatStatus::E_FREE)
+//        hide();
+//    else
+//        show();
+
+//    ui->title->setText(title);
+//    ui->progressBar->setValue(percentage);
+//    ui->debug_info->setText(dmsg);
+}
+
+void LotroProcessDialog::mouseMoveEvent(QMouseEvent *event)
+{
+    if (event->buttons() & Qt::LeftButton) {
+        move(event->globalPos() - dragPosition);
+//        app->window.move(event->globalPos() - dragPosition +
+//                         QPoint((width() - app->window.width()) / 2, (height() - app->window.height()) / 2)
+//                         );
+        event->accept();
+    }
+}
+
+LotroProcessDialog::~LotroProcessDialog()
+{
+    delete ui;
+}

+ 5 - 5
src/Legacy-advanced/widgets/processdialog.h → src/Legacy-advanced/widgets/lotroprocessdialog.h

@@ -9,15 +9,15 @@ namespace Ui {
 class ProcessDialog;
 }
 
-class LegacyApp;
+class LotroManager;
 
-class ProcessDialog : public QDialog
+class LotroProcessDialog : public QDialog
 {
     Q_OBJECT
 
 public:
-    explicit ProcessDialog(LegacyApp *app_, QWidget *parent = 0);
-    ~ProcessDialog();
+    explicit LotroProcessDialog(LotroManager* mgr, QWidget *parent = 0);
+    ~LotroProcessDialog();
 
 protected:
     void mouseMoveEvent(QMouseEvent *event) override;
@@ -30,7 +30,7 @@ private:
     Ui::ProcessDialog *ui;
     QMovie loader;
 
-    LegacyApp* app;
+    LotroManager* lotro_manager;
     QPoint dragPosition;
     QTimer uiUpdateTimer;
 };

+ 45 - 46
src/Legacy-advanced/widgets/mainwindow.cpp

@@ -12,28 +12,33 @@
 #include <QDesktopWidget>
 #include <QtConcurrent/QtConcurrent>
 
-MainWindow::MainWindow(LotroManager* mgr, QSettings* settings, QWidget *parent) :
-    QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint), app(app),
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
     ui(new Ui::MainWindow), menuHoverWidget(nullptr), menuHoverWidgetAnimation(nullptr)
 {
+    ui->setupUi(this);
 
-    QDebug << "Initialising Settings module";
+    qDebug() << "Initialising Settings module";
     QSettings *settings = new QSettings(qApp->applicationDirPath() + "/legacy_v2.ini", QSettings::IniFormat);
 
 
-    QDebug << "Creating lotro manager instance & thread";
+    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);
+    QObject::connect(lotro_mgr_thread, &QThread::finished, lotro_mgr, &QObject::deleteLater, Qt::QueuedConnection);
     lotro_mgr->moveToThread(lotro_mgr_thread);
-    lotro_mgr_thread->run();
+    lotro_mgr_thread->start();
 
-    QDebug << "Creating widgets";
+    qDebug() << "Creating widgets";
+    qDebug() << "1";
     browse_widget = new BrowseWidget(lotro_mgr, settings, this);
+    qDebug() << "2";
     import_widget = new ImportWidget(lotro_mgr, settings, this);
+    qDebug() << "3";
     export_widget = new ExportWidget(lotro_mgr, settings, this);
+    qDebug() << "4";
     manage_widget = new ManageWidget(lotro_mgr, settings, this);
-
+    qDebug() << "Done. Adding to layouts";
     ui->content_layout->addWidget(export_widget);
     ui->content_layout->addWidget(import_widget);
     ui->content_layout->addWidget(manage_widget);
@@ -48,16 +53,17 @@ MainWindow::MainWindow(LotroManager* mgr, QSettings* settings, QWidget *parent)
     changeFontSizeRecursive(100, this);
 
     qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-    background = new QPixmap();
-    background->load(":/assets/backgrounds/bg" + QString::number(qrand() % MAX_PIXMAP_ID + 1) + ".png");
-    setupWindowBackgroundAndMask();
+    current_bg_id = qrand() % MAX_PIXMAP_ID + 1;
+    QPixmap background(":/backgrounds/bg" + QString::number(current_bg_id) + ".png");
+    setupWindowBackgroundAndMask(background);
+
     setupMenuHoverWidget();
 
     updateGeometry();
     repaint();
 
     qDebug() << "Initialising background updates";
-    background_update_timer.setInterval(30 * 1000);
+    background_update_timer.setInterval(20 * 1000);
     connect(&background_update_timer, &QTimer::timeout, this, &MainWindow::randomChangeBackground);
     background_update_timer.start();
 
@@ -94,7 +100,7 @@ void MainWindow::resizeEvent(QResizeEvent * event)
 
     ui->content_area->move(width * 25 / 2000, height * 250 / 1296);
     ui->content_area->resize(width * 1950 / 2000, height * 1000 / 1296);
-    setupWindowBackgroundAndMask();
+    setupWindowBackgroundAndMask(current_bg);
 }
 
 void MainWindow::randomChangeBackground()
@@ -104,42 +110,33 @@ void MainWindow::randomChangeBackground()
 
     qDebug() << "Starting background update";
 
-    if (fade_animation_timer.isActive()) {
-        qDebug() << "MainWindow::startBackgroundUpdate() - cannot start, because update is still active";
-        return;
-    }
 
-    next_pixmap_opacity = 0;
     int next_pixmap_id = qrand() % MAX_PIXMAP_ID + 1;
-
-    if (!next_pixmap)
-        next_pixmap = new QPixmap();
-
-    next_pixmap->load(":/assets/backgrounds/bg" + QString::number(next_pixmap_id) + ".png");
-    qDebug() << "Next pixmap id" << next_pixmap_id << "!";
-
-    if (next_pixmap->isNull()) {
-        qDebug() << "Incorrect pixmap id " << next_pixmap_id << "!";
-        return;
+    while (next_pixmap_id == current_bg_id) {
+        next_pixmap_id = qrand() % MAX_PIXMAP_ID + 1;
     }
+    qDebug() << "Next background id = " << next_pixmap_id;
+
+    QPixmap *cur_bg = new QPixmap(current_bg.scaled(size()));
+    QPixmap *new_bg= new QPixmap(QPixmap(":/backgrounds/bg" + QString::number(next_pixmap_id) + ".png").scaled(size()));
+    current_bg_id = next_pixmap_id;
 
-    QtConcurrent::run([this](){
-        qDebug() << "Starting background update";
-        while (next_pixmap_opacity < 1 && qApp) {
-            if (!qApp)
-                return;
+    QtConcurrent::run([cur_bg, new_bg, this](){
+        const int iterations_num = 100;
+        const int iteration_sleep = 75;
 
+        for (int i = 0; i < iterations_num && qApp; i++) {
             QPainter painter;
-            painter.begin(background);
-            painter.setOpacity(next_pixmap_opacity);
+            painter.begin(cur_bg);
+            painter.setOpacity(double(10 + i) / double(iterations_num));
             painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
-            painter.drawPixmap(0,0, *next_pixmap);
+            painter.drawPixmap(0,0, *new_bg);
             painter.end();
-
-            setupWindowBackgroundAndMask();
-            next_pixmap_opacity += 0.005;
-            QThread::msleep(50);
+            QMetaObject::invokeMethod(this, "setupWindowBackgroundAndMask", Qt::QueuedConnection, Q_ARG(QPixmap, *cur_bg));
+            QThread::msleep(iteration_sleep);
         }
+        delete cur_bg;
+        delete new_bg;
         qDebug() << "Background update finished";
     });
 }
@@ -179,9 +176,11 @@ void MainWindow::onHoverMenuentry()
     moveMenuHoverWidget(MenuEntry::getHoverLabel());
 }
 
-void MainWindow::setupWindowBackgroundAndMask()
+void MainWindow::setupWindowBackgroundAndMask(QPixmap background)
 {
-    current_bg = background->scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+    if (!qApp)
+        return;
+    current_bg = background.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     current_mask = current_bg.mask();
     setMask(current_mask);
 
@@ -243,10 +242,10 @@ void MainWindow::checkMenuIsHovered()
 
 void MainWindow::hideAllContentWidgets()
 {
-    export_frame->hide();
-    import_frame->hide();
-    manage_frame->hide();
-    browse_frame->hide();
+    export_widget->hide();
+    import_widget->hide();
+    manage_widget->hide();
+    browse_widget->hide();
 }
 
 void MainWindow::changeFontSizeRecursive(size_t percent, QWidget *widget)

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

@@ -11,7 +11,6 @@
 #include "importwidget.h"
 #include "managewidget.h"
 #include "browsewidget.h"
-#include "processdialog.h"
 
 namespace Ui {
 class MainWindow;
@@ -28,7 +27,7 @@ class MainWindow : public QMainWindow
     };
 
 public:
-    explicit MainWindow(LotroManager* mgr, QSettings* settings, QWidget *parent = 0);
+    explicit MainWindow(QWidget *parent = 0);
     void Init();
     void changeFontSizeRecursive(size_t percent, QWidget* widget);
     ~MainWindow();
@@ -55,9 +54,11 @@ private slots:
 
     void on_minimizeButton_clicked();
 
-private:
-    void setupWindowBackgroundAndMask();
 
+private slots:
+    void setupWindowBackgroundAndMask(QPixmap background);
+
+private:
     void setupMenuHoverWidget();
 
     void moveMenuHoverWidget(MenuEntry* target);
@@ -84,15 +85,10 @@ private:
 
     QPoint dragPosition;
 
-    QPixmap *background;
-    QPixmap *next_pixmap {nullptr};
-
+    int current_bg_id;
     QPixmap current_bg;
     QBitmap current_mask;
-
     QTimer background_update_timer;
-    QTimer fade_animation_timer;
-    double next_pixmap_opacity;
 
     const int MAX_PIXMAP_ID = 9;
 

+ 0 - 114
src/Legacy-advanced/widgets/processdialog.cpp

@@ -1,114 +0,0 @@
-#include "gui\processdialog.h"
-#include "ui_processdialog.h"
-#include <QPixmap>
-#include <QBitmap>
-#include <QMouseEvent>
-#include "legacyapp.h"
-#include <QTextCodec>
-using namespace LOTRO_DAT;
-
-ProcessDialog::ProcessDialog(LegacyApp *app_, QWidget *parent) :
-    QDialog(parent),
-    ui(new Ui::ProcessDialog), app(app_)
-{
-    ui->setupUi(this);
-    setModal(true);
-    setWindowTitle("Выполнение операции...");
-    QPixmap background(":/assets/backgrounds/process_dialog.png");
-
-    QPixmap current_bg = background.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-    QBitmap current_mask = current_bg.mask();
-    setMask(current_mask);
-
-    QPalette palette;
-    palette.setBrush(QPalette::Window, current_bg);
-    setPalette(palette);
-
-    loader.setFileName(":/assets/backgrounds/loading-gear.gif");
-    ui->loader->setMovie(&loader);
-    loader.setScaledSize(ui->loader->size());
-    loader.start();
-
-    uiUpdateTimer.setInterval(30);
-    connect(&uiUpdateTimer, &QTimer::timeout, this, &ProcessDialog::updateUI);
-    uiUpdateTimer.start();
-}
-
-void ProcessDialog::mousePressEvent(QMouseEvent *event)
-{
-    if (event->button() == Qt::LeftButton) {
-        dragPosition = event->globalPos() - frameGeometry().topLeft();
-        event->accept();
-    }
-}
-
-void ProcessDialog::updateUI()
-{
-    if (!qApp)
-        return;
-
-    std::string debug_msg = app->client_local_dat.GetStatusModule().GetDebugMessage();
-    QTextCodec *codec = QTextCodec::codecForName("UTF8");
-    QByteArray ba(debug_msg.c_str());
-    QString dmsg = codec->toUnicode(ba);
-
-    int percentage = app->client_local_dat.GetStatusModule().GetPercentage();
-
-    DatStatus::DAT_STATUS status = app->client_local_dat.GetStatusModule().GetStatus();
-    QString title = "";
-
-    switch (status) {
-    case DatStatus::E_INITIALISING:
-        title = "Инициализация";
-        break;
-    case DatStatus::E_EXTRACTING:
-        title = "Извлечение данных";
-        break;
-    case DatStatus::E_PATCHING:
-        title = "Применение патча";
-        break;
-    case DatStatus::E_COMMITING:
-        title = "Фиксация данных";
-        break;
-    case DatStatus::E_BACKUP_CREATING:
-        title = "Создание резервной копии";
-        break;
-    case DatStatus::E_BACKUP_REMOVING:
-        title = "Удаление резервной копии";
-        break;
-    case DatStatus::E_GATHERING_INFO:
-        title = "Сбор информации ядра";
-        break;
-    case DatStatus::E_FREE:
-        title = "Свободен";
-        break;
-    default:
-        title = "Неизвестная операция";
-        break;
-    }
-
-    if (status == DatStatus::E_FREE)
-        hide();
-    else
-        show();
-
-    ui->title->setText(title);
-    ui->progressBar->setValue(percentage);
-    ui->debug_info->setText(dmsg);
-}
-
-void ProcessDialog::mouseMoveEvent(QMouseEvent *event)
-{
-    if (event->buttons() & Qt::LeftButton) {
-        move(event->globalPos() - dragPosition);
-        app->window.move(event->globalPos() - dragPosition +
-                         QPoint((width() - app->window.width()) / 2, (height() - app->window.height()) / 2)
-                         );
-        event->accept();
-    }
-}
-
-ProcessDialog::~ProcessDialog()
-{
-    delete ui;
-}