Ver Fonte

Updated MenuEntry class to be more adaptive to use

Ivan Arkhipov há 5 anos atrás
pai
commit
0bffd5b6c2

+ 41 - 16
src/Legacy/widgets/mainwindow.cpp

@@ -18,6 +18,7 @@
 #include <QtConcurrent/QtConcurrent>
 #include <QGraphicsBlurEffect>
 #include <QFont>
+#include <QFontDatabase>
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
@@ -25,6 +26,9 @@ MainWindow::MainWindow(QWidget *parent) :
 {
     setObjectName("ApplicationMainWindow");
     ui->setupUi(this);
+    currently_active_entry = ui->menuentry_1;
+    currently_hover_entry = nullptr;
+
     qDebug() << "Initialising Settings module";
     QSettings *settings = new QSettings(qApp->applicationDirPath() + "/legacy_v2.ini", QSettings::IniFormat);
 
@@ -117,25 +121,39 @@ void MainWindow::resizeEvent(QResizeEvent * event)
     int height = event->size().height();
 
     double dpi = qApp->desktop()->physicalDpiX();
+    dpi = 96;
     const double default_dpi = 96;
     qDebug() << "DPI IS" << dpi;
 
     window_width = width;
     window_height = height;
 
+    pixels_in_12_pt = floor(default_pixels_in_12_pt * window_width * dpi / (default_window_width * default_dpi)+ 0.0001);
     pixels_in_11_pt = floor(default_pixels_in_11_pt * window_width * dpi / (default_window_width * default_dpi)+ 0.0001);
     pixels_in_10_pt = floor(default_pixels_in_10_pt * window_width * dpi / (default_window_width * default_dpi) + 0.0001);
     pixels_in_9_pt = floor(default_pixels_in_9_pt * window_width * dpi / (default_window_width * default_dpi) + 0.0001);
     pixels_in_8_pt = floor(default_pixels_in_8_pt * window_width * dpi / (default_window_width * default_dpi) + 0.0001);
+    pixels_in_7_pt = floor(default_pixels_in_7_pt * window_width * dpi / (default_window_width * default_dpi) + 0.0001);
+    pixels_in_6_pt = floor(default_pixels_in_6_pt * window_width * dpi / (default_window_width * default_dpi) + 0.0001);
+
+//    qDebug() << "AAAAAAAAAAAAAA: " << pixels_in_6_pt << " " << pixels_in_7_pt << " " << pixels_in_8_pt << " " << pixels_in_9_pt << " " << pixels_in_10_pt << " " << pixels_in_11_pt << " " << pixels_in_12_pt;
 
-    ui->menu_widget->move(width * 320 / 1000, height * 34 / 648);
-    ui->menu_widget->resize(width * 650 / 1000, height * 53 / 648);
+//    QMessageBox::information(nullptr, "DEBUG INFO",
+//                             "Window:" + QString::number(window_width) + "x" + QString::number(window_height) + "\n" +
+//                             "Screen:" + QString::number(qApp->desktop()->screenGeometry().width()) + "x" + QString::number(qApp->desktop()->screenGeometry().height()) + "\n" +
+//                             "DPI: " + QString::number(dpi) + "\n" +
+//                             "PixelsIn12Pt: " + QString::number(pixels_in_12_pt));
 
-    ui->content_area->move(0, height * 110 / 648);
-    ui->content_area->resize(width * 1000 / 1000, height * 538 / 648);
+    ui->menu_widget->move(width * 320 / default_window_width, height * 34 / default_window_height);
+    ui->menu_widget->resize(width * 650 / default_window_width, height * 53 / default_window_height);
+
+    ui->content_area->move(0, height * 110 / default_window_height);
+    ui->content_area->resize(width * 1000 / default_window_width, height * 538 / default_window_height);
     setupWindowBackgroundAndMask(current_bg);
     choose_locale_dialog->resize(event->size());
 
+    ui->closeButton->setMinimumSize(width * 20 / default_window_width, height * 20 / default_window_height);
+    ui->minimizeButton->setMinimumSize(width * 20 / default_window_width, height * 20 / default_window_height);
     updateFontSizes();
 }
 
@@ -186,31 +204,38 @@ MainWindow::~MainWindow()
 
 void MainWindow::on_menuentry_1_clicked()
 {
+    currently_active_entry = ui->menuentry_1;
     hideAllContentWidgets();
     status_widget->show();
 }
 
 void MainWindow::on_menuentry_2_clicked()
 {
+    currently_active_entry = ui->menuentry_2;
     hideAllContentWidgets();
-    settings_widget->show();
+    rusification_widget->show();
 }
 
 void MainWindow::on_menuentry_3_clicked()
 {
+    currently_active_entry = ui->menuentry_3;
     hideAllContentWidgets();
-    rusification_widget->show();
+    settings_widget->show();
 }
 
 void MainWindow::on_menuentry_4_clicked()
 {
+    currently_active_entry = ui->menuentry_4;
     hideAllContentWidgets();
     help_widget->show();
 }
 
-void MainWindow::onHoverMenuentry()
+void MainWindow::onHoverMenuentry(MenuEntry *hovered_entry)
 {
-    moveMenuHoverWidget(MenuEntry::getHoverLabel());
+    if (currently_hover_entry != hovered_entry) {
+        currently_hover_entry = hovered_entry;
+        moveMenuHoverWidget(hovered_entry);
+    }
 }
 
 void MainWindow::setupWindowBackgroundAndMask(QPixmap background)
@@ -234,15 +259,15 @@ void MainWindow::makeConnections()
 void MainWindow::setupMenuHoverWidget()
 {
     menuHoverWidget = new QWidget(ui->menu_widget);
-    menuHoverWidget->setStyleSheet("background-color: rgba(55, 37, 31, 250);");
+    menuHoverWidget->setStyleSheet("background-color: rgba(55, 37, 31, 230);");
     menuHoverWidget->resize(0, 0);
 
-    connect(ui->menuentry_1, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry);
-    connect(ui->menuentry_2, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry);
-    connect(ui->menuentry_3, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry);
-    connect(ui->menuentry_4, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry);
+    connect(ui->menuentry_1, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
+    connect(ui->menuentry_2, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
+    connect(ui->menuentry_3, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
+    connect(ui->menuentry_4, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
 
-    MenuEntry::setActiveLabel(ui->menuentry_1);
+    currently_active_entry = ui->menuentry_1;
     menu_hover_checker_timer.setInterval(500);
     connect(&menu_hover_checker_timer, &QTimer::timeout, this, &MainWindow::checkMenuIsHovered);
     menu_hover_checker_timer.start();
@@ -277,8 +302,8 @@ void MainWindow::checkMenuIsHovered()
     QWidget *hovered = qApp->widgetAt(pos);
     if (!hovered || hovered->objectName().size() < 4 ||
             (hovered->objectName().left(9) != "menuentry" && hovered->objectName() != "menu_widget")) {
-        moveMenuHoverWidget(MenuEntry::getActiveLabel());
-        MenuEntry::setHoverLabel(nullptr);
+        moveMenuHoverWidget(currently_active_entry);
+        currently_hover_entry = nullptr;
     }
 }
 

+ 4 - 1
src/Legacy/widgets/mainwindow.h

@@ -54,7 +54,7 @@ private slots:
 
     void on_menuentry_4_clicked();
 
-    void onHoverMenuentry();
+    void onHoverMenuentry(MenuEntry* hovered_entry);
 
     void on_closeButton_clicked();
 
@@ -77,6 +77,9 @@ private:
 
     void setEventFilterRecursive(QObject* widget);
 private:    
+    MenuEntry* currently_active_entry;
+    MenuEntry* currently_hover_entry;
+
     PatchDownloader *patch_updater;
     LotroDatManager *lotro_manager;
     QThread *lotro_functions_thread;

+ 5 - 5
src/Legacy/widgets/mainwindow.ui

@@ -108,7 +108,7 @@
     <property name="styleSheet">
      <string notr="true">border-image:transparent;</string>
     </property>
-    <layout class="QHBoxLayout" name="horizontalLayout" stretch="6,7,8,6,5">
+    <layout class="QHBoxLayout" name="horizontalLayout" stretch="6,0,8,6,5">
      <property name="spacing">
       <number>10</number>
      </property>
@@ -159,7 +159,7 @@
         <string notr="true">color: rgb(255, 255, 255);</string>
        </property>
        <property name="text">
-        <string>    главная    </string>
+        <string>  главная  </string>
        </property>
        <property name="scaledContents">
         <bool>true</bool>
@@ -201,7 +201,7 @@
         <string notr="true">color: rgb(255, 255, 255);</string>
        </property>
        <property name="text">
-        <string>  настройки  </string>
+        <string>  русификация  </string>
        </property>
        <property name="scaledContents">
         <bool>true</bool>
@@ -217,7 +217,7 @@
      <item>
       <widget class="MenuEntry" name="menuentry_3">
        <property name="sizePolicy">
-        <sizepolicy hsizetype="Ignored" vsizetype="Expanding">
+        <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
@@ -243,7 +243,7 @@
         <string notr="true">color: rgb(255, 255, 255);</string>
        </property>
        <property name="text">
-        <string notr="true">помощь</string>
+        <string notr="true">  помощь  </string>
        </property>
        <property name="scaledContents">
         <bool>true</bool>

+ 3 - 32
src/Legacy/widgets/menuentry.cpp

@@ -2,9 +2,6 @@
 #include <QApplication>
 #include <QTimer>
 
-MenuEntry *MenuEntry::active_label = nullptr;
-MenuEntry *MenuEntry::hover_label = nullptr;
-
 MenuEntry::MenuEntry(QWidget* parent, Qt::WindowFlags)
     : QLabel(parent) {
 
@@ -13,42 +10,16 @@ MenuEntry::MenuEntry(QWidget* parent, Qt::WindowFlags)
 
 MenuEntry::~MenuEntry() {}
 
-MenuEntry *MenuEntry::getActiveLabel()
-{
-    return active_label;
-}
-
-void MenuEntry::setActiveLabel(MenuEntry *label)
-{
-    active_label = label;
-}
-
-MenuEntry *MenuEntry::getHoverLabel()
-{
-    return hover_label;
-}
-
-void MenuEntry::setHoverLabel(MenuEntry *label)
-{
-    hover_label = label;
-}
-
 void MenuEntry::mousePressEvent(QMouseEvent* event) {
     event->ignore();
-    if (active_label != this) {
-        active_label = this;
-        emit active_label_changed();
-        emit clicked();
-    }
+    emit entryIsPressed(this);
+    emit clicked();
 }
 
 void MenuEntry::mouseMoveEvent(QMouseEvent *event)
 {
     event->ignore();
-    if (hover_label != this) {
-        hover_label = this;
-        emit hover_label_changed();
-    }
+    emit entryIsHovered(this);
 }
 
 void MenuEntry::on_clicked()

+ 2 - 8
src/Legacy/widgets/menuentry.h

@@ -12,15 +12,11 @@ class MenuEntry : public QLabel {
 public:
     explicit MenuEntry(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
     ~MenuEntry();
-    static MenuEntry *getActiveLabel();
-    static void setActiveLabel(MenuEntry *label);
-    static MenuEntry *getHoverLabel();
-    static void setHoverLabel(MenuEntry *label);
 
 signals:
     void clicked();
-    void active_label_changed();
-    void hover_label_changed();
+    void entryIsPressed(MenuEntry*);
+    void entryIsHovered(MenuEntry*);
 
 protected:
     void mousePressEvent(QMouseEvent* event);
@@ -30,8 +26,6 @@ private slots:
     void on_clicked();
 
 private:
-    static MenuEntry *active_label;
-    static MenuEntry *hover_label;
     const QString default_stylesheet = "color:rgb(255, 255, 255);";
     const QString active_stylesheet = "color:rgb(200, 200, 200);";
 };