소스 검색

gradient editor now zoomable

Nicolas Winkler 4 년 전
부모
커밋
ef409a3b90
8개의 변경된 파일242개의 추가작업 그리고 57개의 파일을 삭제
  1. 2 2
      include/Almond.h
  2. 15 0
      include/GradientMenu.h
  3. 1 0
      resources/Almond.qrc
  4. 76 0
      resources/icons/zoom_zero.svg
  5. 53 9
      src/GradientMenu.cpp
  6. 4 1
      src/GradientWidget.cpp
  7. 25 18
      ui/Almond.ui
  8. 66 27
      ui/GradientMenu.ui

+ 2 - 2
include/Almond.h

@@ -75,11 +75,11 @@ public:
     ~Almond(void);
 
     void submitBackgroundTask(BackgroundTask* task);
-    void stopBackgroundTask();
+    void stopBackgroundTask(void);
 
     void closeEvent(QCloseEvent* ce) override;
 
-    bool eventFilter(QObject *target, QEvent *event);
+    bool eventFilter(QObject *target, QEvent *event) override;
 
     void submenuOK(int smIndex);
     void imageExportOk(void);

+ 15 - 0
include/GradientMenu.h

@@ -12,6 +12,20 @@ namespace Ui {
 class GradientMenu;
 }
 
+
+class MinHeightWrapperWidget :
+    public QWidget
+{
+    Q_OBJECT
+    int minHeight;
+    QWidget* widget;
+public:
+    MinHeightWrapperWidget(QWidget* contains, QWidget* parent);
+    QSize minimumSizeHint(void) const override;
+    QSize sizeHint(void) const override;
+};
+
+
 class GradientMenu : public QWidget
 {
     Q_OBJECT
@@ -41,6 +55,7 @@ private slots:
     void on_maxValSpb_valueChanged(double maxVal);
     void on_zoomOutBtn_clicked();
     void on_zoomInBtn_clicked();
+    void on_zoomResetBtn_clicked();
 };
 
 #endif // GRADIENTMENU_H

+ 1 - 0
resources/Almond.qrc

@@ -4,6 +4,7 @@
         <file alias="icon@2x">Almond.png</file>
         <file alias="zoom_in">icons/zoom_in.svg</file>
         <file alias="zoom_out">icons/zoom_out.svg</file>
+        <file alias="zoom_zero">icons/zoom_zero.svg</file>
     </qresource>
     <qresource prefix="/gradients">
         <file alias="oldschool">gradients/oldschool.xml</file>

+ 76 - 0
resources/icons/zoom_zero.svg

@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
+   sodipodi:docname="zoom_zero.svg"
+   width="210mm"
+   height="297mm"
+   viewBox="0 0 210 297"
+   version="1.1"
+   id="svg8">
+  <sodipodi:namedview
+     inkscape:current-layer="layer1"
+     inkscape:window-maximized="0"
+     inkscape:window-y="34"
+     inkscape:window-x="0"
+     inkscape:cy="561.25984"
+     inkscape:cx="36.27941"
+     inkscape:zoom="0.74742565"
+     showgrid="false"
+     id="namedview10"
+     inkscape:window-height="1360"
+     inkscape:window-width="2552"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0"
+     guidetolerance="10"
+     gridtolerance="10"
+     objecttolerance="10"
+     borderopacity="1"
+     bordercolor="#666666"
+     pagecolor="#ffffff" />
+  <defs
+     id="defs2" />
+  <metadata
+     id="metadata5">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1">
+    <ellipse
+       style="fill:none;stroke:#000000;stroke-width:16;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal"
+       id="path4526"
+       cx="69.093491"
+       cy="112.36012"
+       rx="58.992577"
+       ry="58.99258" />
+    <path
+       style="fill:none;stroke:#000000;stroke-width:16.00000045;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;paint-order:stroke fill markers"
+       d="m 111.18412,154.81261 72.69731,76.97362"
+       id="path4584" />
+    <ellipse
+       ry="33.163971"
+       rx="21.126312"
+       cy="112.36012"
+       cx="69.093491"
+       id="path12"
+       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:13.8082;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+    <path
+       id="path863"
+       d="M 57.790024,90.093966 81.672225,136.93685"
+       style="fill:none;stroke:#000000;stroke-width:7.93750002;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" />
+  </g>
+</svg>

+ 53 - 9
src/GradientMenu.cpp

@@ -6,6 +6,7 @@
 #include <QFile>
 #include <QMessageBox>
 #include <QFileDialog>
+#include <QTextEdit>
 
 const QString GradientMenu::presetNames[] = {
     "blue gold",
@@ -17,6 +18,38 @@ const QString GradientMenu::presetNames[] = {
 };
 
 
+MinHeightWrapperWidget::MinHeightWrapperWidget(QWidget* contains, QWidget* parent) :
+    QWidget{ parent },
+    widget{ contains }
+{
+    this->setContentsMargins(0, 0, 0, 0);
+    resize(300, 1200);
+    QVBoxLayout* l = new QVBoxLayout(this);
+    l->setStretch(0, 1);
+    this->setLayout(l);
+    widget->setParent(this);
+    widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+    //this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    this->layout()->update();
+}
+
+
+QSize MinHeightWrapperWidget::minimumSizeHint(void) const
+{
+    return QSize(300, 1200);
+    QSize minH = widget->minimumSizeHint();
+    return QSize(minH.width(), qMax(minH.height(), minHeight));
+}
+
+
+QSize MinHeightWrapperWidget::sizeHint(void) const
+{
+    return QSize(300, 1200);
+    QSize minH = widget->sizeHint();
+    return QSize(minH.width(), qMax(minH.height(), minHeight));
+}
+
+
 GradientMenu::GradientMenu(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::GradientMenu)
@@ -135,22 +168,33 @@ void GradientMenu::on_maxValSpb_valueChanged(double maxVal)
     ui->gradientWidget->setGradient(std::move(g));
 }
 
+
 void GradientMenu::on_zoomOutBtn_clicked()
 {
-    QSize size = ui->scrollArea->size();
-    if (size.height() * 0.9 >= ui->gradientWidget->sizeHint().height()) {
-        ui->gradientWidget->resize(size.width(), int(size.height() * 0.9));
+    int currentHeight = ui->gradientWidget->height();
+    int minHeight = ui->gradientWidget->sizeHint().height();
+    if (currentHeight * 0.9 >= minHeight) {
+        ui->gradientWidget->setFixedHeight(int(currentHeight * 0.9));
     }
     else {
-        ui->gradientWidget->resize(size.width(), ui->gradientWidget->sizeHint().height());
+        ui->gradientWidget->setFixedHeight(minHeight);
     }
-    ui->scrollArea->updateGeometry();
 }
 
+
 void GradientMenu::on_zoomInBtn_clicked()
 {
-    QSize size = ui->gradientWidget->size();
-    if (size.height() < 16000)
-        ui->gradientWidget->resize(size.width(), int(size.height() * 1.1));
-    ui->scrollArea->updateGeometry();
+    int currentHeight = ui->gradientWidget->height();
+    int maxHeight = 16000;
+    if (currentHeight * 1.1 <= maxHeight)
+        ui->gradientWidget->setFixedHeight(currentHeight * 1.1);
+    else
+        ui->gradientWidget->setFixedHeight(maxHeight);
+}
+
+
+void GradientMenu::on_zoomResetBtn_clicked()
+{
+    ui->gradientWidget->setMinimumHeight(ui->gradientWidget->minimumSizeHint().height());
+    ui->gradientWidget->setMaximumHeight(16000);
 }

+ 4 - 1
src/GradientWidget.cpp

@@ -271,7 +271,10 @@ QSize GradientWidget::sizeHint(void) const
                     QSizePolicy::PushButton,
                     Qt::Horizontal);
     }
-    return QSize{ int(handleWidth * 1.1 + spacing), handleHeight };
+    int spacingV = this->style()->pixelMetric(
+                QStyle::PM_LayoutVerticalSpacing);
+    return QSize{ int(handleWidth * 1.1 + spacing),
+        2 * spacingV + 3 * handleHeight };
 }
 
 

+ 25 - 18
ui/Almond.ui

@@ -62,44 +62,51 @@
           <string>Zoom</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_2">
-          <item row="1" column="1">
-           <widget class="QPushButton" name="zoom_in">
+          <item row="1" column="3">
+           <widget class="QPushButton" name="zoom_out">
             <property name="icon">
              <iconset resource="../resources/Almond.qrc">
-              <normaloff>:/icons/zoom_in</normaloff>:/icons/zoom_in</iconset>
+              <normaloff>:/icons/zoom_out</normaloff>:/icons/zoom_out</iconset>
             </property>
             <property name="iconSize">
              <size>
-              <width>24</width>
-              <height>24</height>
+              <width>32</width>
+              <height>32</height>
              </size>
             </property>
            </widget>
           </item>
-          <item row="1" column="2">
-           <widget class="QPushButton" name="zoom_out">
+          <item row="1" column="1">
+           <widget class="QPushButton" name="resetZoom">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
             <property name="icon">
              <iconset resource="../resources/Almond.qrc">
-              <normaloff>:/icons/zoom_out</normaloff>:/icons/zoom_out</iconset>
+              <normaloff>:/icons/zoom_zero</normaloff>:/icons/zoom_zero</iconset>
             </property>
             <property name="iconSize">
              <size>
-              <width>24</width>
-              <height>24</height>
+              <width>32</width>
+              <height>32</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="1" column="0">
-           <widget class="QPushButton" name="resetZoom">
-            <property name="sizePolicy">
-             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-              <horstretch>0</horstretch>
-              <verstretch>0</verstretch>
-             </sizepolicy>
+           <widget class="QPushButton" name="zoom_in">
+            <property name="icon">
+             <iconset resource="../resources/Almond.qrc">
+              <normaloff>:/icons/zoom_in</normaloff>:/icons/zoom_in</iconset>
             </property>
-            <property name="text">
-             <string>Reset Zoom</string>
+            <property name="iconSize">
+             <size>
+              <width>32</width>
+              <height>32</height>
+             </size>
             </property>
            </widget>
           </item>

+ 66 - 27
ui/GradientMenu.ui

@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>302</width>
+    <width>427</width>
     <height>508</height>
    </rect>
   </property>
@@ -73,30 +73,82 @@
      <item>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
-        <widget class="QPushButton" name="zoomOutBtn">
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QPushButton" name="zoomInBtn">
          <property name="icon">
           <iconset resource="../resources/Almond.qrc">
-           <normaloff>:/icons/zoom_out</normaloff>:/icons/zoom_out</iconset>
+           <normaloff>:/icons/zoom_in</normaloff>:/icons/zoom_in</iconset>
+         </property>
+         <property name="iconSize">
+          <size>
+           <width>32</width>
+           <height>32</height>
+          </size>
          </property>
         </widget>
        </item>
        <item>
-        <widget class="QPushButton" name="zoomInBtn">
+        <widget class="QPushButton" name="zoomResetBtn">
          <property name="icon">
           <iconset resource="../resources/Almond.qrc">
-           <normaloff>:/icons/zoom_in</normaloff>:/icons/zoom_in</iconset>
+           <normaloff>:/icons/zoom_zero</normaloff>:/icons/zoom_zero</iconset>
+         </property>
+         <property name="iconSize">
+          <size>
+           <width>32</width>
+           <height>32</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="zoomOutBtn">
+         <property name="icon">
+          <iconset resource="../resources/Almond.qrc">
+           <normaloff>:/icons/zoom_out</normaloff>:/icons/zoom_out</iconset>
+         </property>
+         <property name="iconSize">
+          <size>
+           <width>32</width>
+           <height>32</height>
+          </size>
          </property>
         </widget>
        </item>
+       <item>
+        <spacer name="verticalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
       </layout>
      </item>
      <item>
       <widget class="QScrollArea" name="scrollArea">
-       <property name="verticalScrollBarPolicy">
-        <enum>Qt::ScrollBarAlwaysOn</enum>
+       <property name="frameShape">
+        <enum>QFrame::NoFrame</enum>
        </property>
-       <property name="sizeAdjustPolicy">
-        <enum>QAbstractScrollArea::AdjustToContents</enum>
+       <property name="lineWidth">
+        <number>0</number>
        </property>
        <property name="widgetResizable">
         <bool>true</bool>
@@ -106,26 +158,13 @@
          <rect>
           <x>0</x>
           <y>0</y>
-          <width>245</width>
-          <height>359</height>
+          <width>361</width>
+          <height>213</height>
          </rect>
         </property>
-        <layout class="QVBoxLayout" name="verticalLayout_3">
-         <item>
-          <widget class="GradientWidget" name="gradientWidget" native="true">
-           <property name="sizePolicy">
-            <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
-             <horstretch>0</horstretch>
-             <verstretch>0</verstretch>
-            </sizepolicy>
-           </property>
-           <property name="minimumSize">
-            <size>
-             <width>0</width>
-             <height>300</height>
-            </size>
-           </property>
-          </widget>
+        <layout class="QGridLayout" name="gridLayout_2">
+         <item row="0" column="0">
+          <widget class="GradientWidget" name="gradientWidget" native="true"/>
          </item>
         </layout>
        </widget>