Browse Source

Added tooltipped button

Ivan Arkhipov 3 years ago
parent
commit
4518b37163

+ 2 - 1
Legacy_v2.pro

@@ -18,4 +18,5 @@ SUBDIRS += \
 #    src/Legacy-advanced \
     src/LegacyLauncher
 
-CONFIG += qt
+CONFIG += qt \
+    qt

+ 2 - 0
src/Legacy/Legacy.pro

@@ -34,6 +34,7 @@ SOURCES += \
     widgets/weeklycodewidget.cpp \
     widgets/dialogwindow.cpp \
     widgets/qsmoothscrollarea.cpp \
+    widgets/tooltipbutton.cpp \
     fonts.cpp \
     legacyapplication.cpp \
     models/settings.cpp \
@@ -60,6 +61,7 @@ HEADERS += \
     widgets/weeklycodewidget.h \
     widgets/dialogwindow.h \
     widgets/qsmoothscrollarea.h \
+    widgets/tooltipbutton.h \
     constants.h \
     fonts.h \
     models/settings.h \

+ 15 - 0
src/Legacy/widgets/statuswidget.cpp

@@ -48,6 +48,21 @@ StatusWidget::StatusWidget(QWidget *parent)
     process_completed_tooltip_hide_timer_.setInterval(4 * 1000); // 4 seconds message "Installation completed" will be shown
     process_completed_tooltip_hide_timer_.stop();
     connect(&process_completed_tooltip_hide_timer_, &QTimer::timeout, this, [this](){unsetToolTipMessage(E_PROCESS); process_completed_tooltip_hide_timer_.stop();});
+
+    ui->texts_block_label->setTooltipParentWidget(this);
+    ui->texts_block_label->setTooltipText("Перевод всех текстовых элементов в игре: названий, квестов, меню и т.д.");
+
+    ui->graphics_block_label->setTooltipParentWidget(this);
+    ui->graphics_block_label->setTooltipText("Переведенные карты локаций и элементы графического интерфейса.");
+
+    ui->video_block_label->setTooltipParentWidget(this);
+    ui->video_block_label->setTooltipText("Переведенные и озвученные видеоролики и кат-сцены.");
+
+    ui->audio_block_label->setTooltipParentWidget(this);
+    ui->audio_block_label->setTooltipText("Переведенные и озвученные реплики персонажей.");
+
+    ui->loadscreens_block_label->setTooltipParentWidget(this);
+    ui->loadscreens_block_label->setTooltipText("Загрузочные экраны от команды Наследия");
 }
 
 StatusWidget::~StatusWidget()

+ 298 - 21
src/Legacy/widgets/statuswidget.ui

@@ -472,7 +472,7 @@ color: black;
 border-radius: 3px;</string>
          </property>
          <property name="currentText">
-          <string>Английскую</string>
+          <string>Английская</string>
          </property>
          <property name="sizeAdjustPolicy">
           <enum>QComboBox::AdjustToContentsOnFirstShow</enum>
@@ -482,17 +482,17 @@ border-radius: 3px;</string>
          </property>
          <item>
           <property name="text">
-           <string>Английскую</string>
+           <string>Английская</string>
           </property>
          </item>
          <item>
           <property name="text">
-           <string>Немецкую</string>
+           <string>Немецкая</string>
           </property>
          </item>
          <item>
           <property name="text">
-           <string>Французскую</string>
+           <string>Французская</string>
           </property>
          </item>
         </widget>
@@ -521,7 +521,7 @@ border-radius: 3px;</string>
      <x>300</x>
      <y>150</y>
      <width>481</width>
-     <height>101</height>
+     <height>281</height>
     </rect>
    </property>
    <property name="styleSheet">
@@ -562,7 +562,7 @@ border-radius: 3px;</string>
      </widget>
     </item>
     <item>
-     <widget class="QWidget" name="graphics_block" native="true">
+     <widget class="QWidget" name="a_texts_block" native="true">
       <layout class="QHBoxLayout" name="horizontalLayout_3">
        <property name="spacing">
         <number>3</number>
@@ -577,13 +577,96 @@ border-radius: 3px;</string>
         <number>0</number>
        </property>
        <item>
-        <widget class="QLabel" name="graphics_block_label">
+        <widget class="TooltipButton" name="texts_block_label">
          <property name="font">
           <font>
            <family>Crimson Text</family>
            <pointsize>12</pointsize>
           </font>
          </property>
+         <property name="autoFillBackground">
+          <bool>false</bool>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">border-bottom: 3px dotted #fff;
+</string>
+         </property>
+         <property name="frameShape">
+          <enum>QFrame::NoFrame</enum>
+         </property>
+         <property name="text">
+          <string>Тексты</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="SwitchButton" name="texts_block_switch" native="true">
+         <property name="minimumSize">
+          <size>
+           <width>110</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="cursor">
+          <cursorShape>PointingHandCursor</cursorShape>
+         </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
+     <widget class="QWidget" name="b_graphics_block" native="true">
+      <layout class="QHBoxLayout" name="horizontalLayout_4">
+       <property name="spacing">
+        <number>3</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="TooltipButton" name="graphics_block_label">
+         <property name="font">
+          <font>
+           <family>Crimson Text</family>
+           <pointsize>12</pointsize>
+          </font>
+         </property>
+         <property name="autoFillBackground">
+          <bool>false</bool>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">border-bottom: 3px dotted #fff;
+</string>
+         </property>
+         <property name="frameShape">
+          <enum>QFrame::NoFrame</enum>
+         </property>
          <property name="text">
           <string>Изображения</string>
          </property>
@@ -593,37 +676,226 @@ border-radius: 3px;</string>
         </widget>
        </item>
        <item>
-        <widget class="QLabel" name="helper_label">
+        <spacer name="horizontalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="SwitchButton" name="graphics_block_switch" native="true">
          <property name="minimumSize">
           <size>
-           <width>20</width>
+           <width>64</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="cursor">
+          <cursorShape>PointingHandCursor</cursorShape>
+         </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
+     <widget class="QWidget" name="c_video_block" native="true">
+      <layout class="QHBoxLayout" name="horizontalLayout_5">
+       <property name="spacing">
+        <number>3</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="TooltipButton" name="video_block_label">
+         <property name="font">
+          <font>
+           <family>Crimson Text</family>
+           <pointsize>12</pointsize>
+          </font>
+         </property>
+         <property name="autoFillBackground">
+          <bool>false</bool>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">border-bottom: 3px dotted #fff;
+</string>
+         </property>
+         <property name="frameShape">
+          <enum>QFrame::NoFrame</enum>
+         </property>
+         <property name="text">
+          <string>Видеоролики</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer_3">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
            <height>20</height>
           </size>
          </property>
-         <property name="maximumSize">
+        </spacer>
+       </item>
+       <item>
+        <widget class="SwitchButton" name="video_block_switch" native="true">
+         <property name="minimumSize">
           <size>
-           <width>20</width>
+           <width>64</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="cursor">
+          <cursorShape>PointingHandCursor</cursorShape>
+         </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
+     <widget class="QWidget" name="d_audio_block" native="true">
+      <layout class="QHBoxLayout" name="horizontalLayout_6">
+       <property name="spacing">
+        <number>3</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="TooltipButton" name="audio_block_label">
+         <property name="font">
+          <font>
+           <family>Crimson Text</family>
+           <pointsize>12</pointsize>
+          </font>
+         </property>
+         <property name="autoFillBackground">
+          <bool>false</bool>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">border-bottom: 3px dotted #fff;
+</string>
+         </property>
+         <property name="frameShape">
+          <enum>QFrame::NoFrame</enum>
+         </property>
+         <property name="text">
+          <string>Озвучка персонажей</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer_5">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
            <height>20</height>
           </size>
          </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="SwitchButton" name="audio_block_switch" native="true">
+         <property name="minimumSize">
+          <size>
+           <width>64</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="cursor">
+          <cursorShape>PointingHandCursor</cursorShape>
+         </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
+     <widget class="QWidget" name="e_loadscreens_block" native="true">
+      <layout class="QHBoxLayout" name="horizontalLayout_7">
+       <property name="spacing">
+        <number>3</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="TooltipButton" name="loadscreens_block_label">
+         <property name="font">
+          <font>
+           <family>Crimson Text</family>
+           <pointsize>12</pointsize>
+          </font>
+         </property>
+         <property name="autoFillBackground">
+          <bool>false</bool>
+         </property>
          <property name="styleSheet">
-          <string notr="true">QLabel#helper_label {
-	background-color: rgba(31, 19, 7, 155);
-	border-radius: 10px;
-	border: 1px solid rgba(149, 149, 149, 155);
-    background-attachment: fixed;
-}</string>
+          <string notr="true">border-bottom: 3px dotted #fff;
+</string>
+         </property>
+         <property name="frameShape">
+          <enum>QFrame::NoFrame</enum>
          </property>
          <property name="text">
-          <string>?</string>
+          <string>Загрузочные экраны</string>
          </property>
          <property name="alignment">
-          <set>Qt::AlignCenter</set>
+          <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
          </property>
         </widget>
        </item>
        <item>
-        <spacer name="horizontalSpacer">
+        <spacer name="horizontalSpacer_6">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
@@ -636,7 +908,7 @@ border-radius: 3px;</string>
         </spacer>
        </item>
        <item>
-        <widget class="SwitchButton" name="widget_3" native="true">
+        <widget class="SwitchButton" name="loadscreens_block_switch" native="true">
          <property name="minimumSize">
           <size>
            <width>64</width>
@@ -691,6 +963,11 @@ border-radius: 3px;</string>
    <header>widgets/switchbutton.h</header>
    <container>1</container>
   </customwidget>
+  <customwidget>
+   <class>TooltipButton</class>
+   <extends>QLabel</extends>
+   <header>widgets/tooltipbutton.h</header>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>

+ 96 - 0
src/Legacy/widgets/tooltipbutton.cpp

@@ -0,0 +1,96 @@
+#include "tooltipbutton.h"
+
+#include <QDebug>
+#include <QPoint>
+#include <QPropertyAnimation>
+
+TooltipButton::TooltipButton(QWidget *parent) : QLabel(parent) {
+    setMouseTracking(true);
+
+    _tooltip_parent_widget = this;
+
+    _tooltip_label = new QLabel(this);
+    _tooltip_label->setText("Tooltip.");
+    _tooltip_label->setMaximumWidth(360);
+    _tooltip_label->setWordWrap(true);
+    _tooltip_label->setStyleSheet("padding: 8px; background-color: #222; border: 1px solid #fff; border-radius: 5px; color: #fff");
+    _tooltip_label->hide();
+
+    _tooltip_label_arrow = new QWidget(this);
+    _tooltip_label_arrow->setStyleSheet("border-image: url(:/buttons/tooltip_triangle.png);");
+    _tooltip_label_arrow->resize(14, 7);
+    _tooltip_label_arrow->hide();
+
+    _tooltip_opacity_effect = new QGraphicsOpacityEffect(this);
+    _tooltip_arrow_opacity_effect = new QGraphicsOpacityEffect(this);
+
+    _tooltip_label->setGraphicsEffect(_tooltip_opacity_effect);
+    _tooltip_label_arrow->setGraphicsEffect(_tooltip_arrow_opacity_effect);
+}
+
+void TooltipButton::enterEvent(QEvent*) {
+   QPropertyAnimation *animation = new QPropertyAnimation(_tooltip_opacity_effect, "opacity");
+   animation->setDuration(300);
+   animation->setStartValue(0);
+   animation->setEndValue(1);
+   animation->setEasingCurve(QEasingCurve::InBack);
+   animation->start(QPropertyAnimation::DeleteWhenStopped);
+   _tooltip_label->show();
+
+   QPropertyAnimation *arrow_animation = new QPropertyAnimation(_tooltip_arrow_opacity_effect, "opacity");
+   arrow_animation->setDuration(300);
+   arrow_animation->setStartValue(0);
+   arrow_animation->setEndValue(1);
+   arrow_animation->setEasingCurve(QEasingCurve::InBack);
+   arrow_animation->start(QPropertyAnimation::DeleteWhenStopped);
+   _tooltip_label_arrow->show();
+}
+
+void TooltipButton::leaveEvent(QEvent*) {
+    QPropertyAnimation *animation = new QPropertyAnimation(_tooltip_opacity_effect, "opacity");
+    animation->setDuration(300);
+    animation->setStartValue(1);
+    animation->setEndValue(0);
+    animation->setEasingCurve(QEasingCurve::InBack);
+    animation->start(QPropertyAnimation::DeleteWhenStopped);
+    connect(animation, &QPropertyAnimation::finished, _tooltip_label, &QLabel::hide);
+
+    QPropertyAnimation *arrow_animation = new QPropertyAnimation(_tooltip_arrow_opacity_effect, "opacity");
+    arrow_animation->setDuration(300);
+    arrow_animation->setStartValue(1);
+    arrow_animation->setEndValue(0);
+    arrow_animation->setEasingCurve(QEasingCurve::InBack);
+    arrow_animation->start(QPropertyAnimation::DeleteWhenStopped);
+    connect(arrow_animation, &QPropertyAnimation::finished, _tooltip_label_arrow, &QLabel::hide);
+}
+
+void TooltipButton::moveEvent(QMoveEvent*) {
+    updateTooltipPosition();
+}
+
+void TooltipButton::resizeEvent(QResizeEvent*) {
+    updateTooltipPosition();
+}
+
+void TooltipButton::setTooltipParentWidget(QWidget *widget) {
+    _tooltip_parent_widget = widget;
+    _tooltip_label->setParent(widget);
+    _tooltip_label_arrow->setParent(widget);
+    updateTooltipPosition();
+}
+
+void TooltipButton::setTooltipText(QString text) {
+    _tooltip_label->setText(text);
+    updateTooltipPosition();
+}
+
+void TooltipButton::updateTooltipPosition() {
+    QPoint pos_global = mapToGlobal((rect().topLeft() + rect().topRight()) / 2);
+    QPoint pos_relative_to_tooltip_parent = _tooltip_parent_widget->mapFromGlobal(pos_global);
+    pos_relative_to_tooltip_parent.rx() -= _tooltip_label->sizeHint().width() / 2;
+    pos_relative_to_tooltip_parent.ry() -= _tooltip_label->sizeHint().height() + 6; // 10 for tooltip arrow
+    _tooltip_label->move(pos_relative_to_tooltip_parent);
+
+    QPoint tooltip_arrow_pos = _tooltip_parent_widget->mapFromGlobal(pos_global) - QPoint(7, 7);
+    _tooltip_label_arrow->move(tooltip_arrow_pos);
+}

+ 39 - 0
src/Legacy/widgets/tooltipbutton.h

@@ -0,0 +1,39 @@
+#ifndef TOOLTIPBUTTON_H
+#define TOOLTIPBUTTON_H
+
+#include <QLabel>
+#include <QGraphicsOpacityEffect>
+
+class TooltipButton : public QLabel
+{
+    Q_OBJECT
+public:
+    explicit TooltipButton(QWidget *parent = nullptr);
+
+    void enterEvent(QEvent *) override;
+
+    void leaveEvent(QEvent *) override;
+
+    void moveEvent(QMoveEvent *) override;
+
+    void resizeEvent(QResizeEvent *) override;
+
+    void setTooltipParentWidget(QWidget *);
+
+    void setTooltipText(QString text);
+
+private:
+    void updateTooltipPosition();
+
+signals:
+
+
+private:
+    QWidget* _tooltip_parent_widget = nullptr;
+    QLabel* _tooltip_label = nullptr;
+    QWidget* _tooltip_label_arrow = nullptr;
+    QGraphicsOpacityEffect *_tooltip_opacity_effect = nullptr;
+    QGraphicsOpacityEffect *_tooltip_arrow_opacity_effect = nullptr;
+};
+
+#endif // TOOLTIPBUTTON_H