Browse Source

gradient editor zoom not yet working

Nicolas Winkler 4 năm trước cách đây
mục cha
commit
6f727c3db1

+ 2 - 0
include/GradientMenu.h

@@ -39,6 +39,8 @@ private slots:
     void on_saveBtn_clicked();
     void on_loadBtn_clicked();
     void on_maxValSpb_valueChanged(double maxVal);
+    void on_zoomOutBtn_clicked();
+    void on_zoomInBtn_clicked();
 };
 
 #endif // GRADIENTMENU_H

+ 2 - 0
libalmond/src/ExportRecipe.cpp

@@ -9,6 +9,7 @@ using alm::XmlException;
 
 std::string ImageExportRecipe::toXml(void) const
 {
+    return "";
 }
 
 
@@ -16,4 +17,5 @@ ImageExportRecipe ImageExportRecipe::fromXml(const std::string& xml)
 {
     tinyxml2::XMLDocument xmlDoc;
     xmlDoc.Parse(xml.c_str());
+    return ImageExportRecipe{};
 }

+ 3 - 2
src/EscapeTimeVisualWidget.cpp

@@ -292,6 +292,7 @@ void EscapeTimeVisualWidget::initializeGL(void)
     "}");
 
     // TODO rewrite this monster
+    // remove hardcoded 256 texture size
     if (!context()->isOpenGLES() &&
         context()->versionFunctions<QOpenGLFunctions_4_0_Core>() != nullptr) {
         bool frag = program->addShaderFromSourceCode(QOpenGLShader::Fragment,
@@ -314,8 +315,8 @@ void EscapeTimeVisualWidget::initializeGL(void)
         "   vec2 size = textureSize(tex, 0);\n"
         "   size = vec2(256.0, 256.0);\n"
         "   vec2 accPoint = texc * size;\n"
-        "   vec2 ip = floor(accPoint);\n"
-        "   vec2 fp = fract(accPoint);\n"
+        "   vec2 ip = floor(accPoint + 0.5);\n"
+        "   vec2 fp = fract(accPoint + 0.5);\n"
         "   vec4 inter = textureGather(tex, ip / size, 0);\n"
         "   vec4 col1 = colorize(inter.x);\n"
         "   vec4 col2 = colorize(inter.y);\n"

+ 20 - 0
src/GradientMenu.cpp

@@ -134,3 +134,23 @@ void GradientMenu::on_maxValSpb_valueChanged(double maxVal)
     Gradient g = Gradient{ old.getPoints(), float(maxVal), old.isRepeat() };
     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));
+    }
+    else {
+        ui->gradientWidget->resize(size.width(), ui->gradientWidget->sizeHint().height());
+    }
+    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();
+}

+ 0 - 6
ui/Almond.ui

@@ -64,9 +64,6 @@
          <layout class="QGridLayout" name="gridLayout_2">
           <item row="1" column="1">
            <widget class="QPushButton" name="zoom_in">
-            <property name="text">
-             <string/>
-            </property>
             <property name="icon">
              <iconset resource="../resources/Almond.qrc">
               <normaloff>:/icons/zoom_in</normaloff>:/icons/zoom_in</iconset>
@@ -81,9 +78,6 @@
           </item>
           <item row="1" column="2">
            <widget class="QPushButton" name="zoom_out">
-            <property name="text">
-             <string/>
-            </property>
             <property name="icon">
              <iconset resource="../resources/Almond.qrc">
               <normaloff>:/icons/zoom_out</normaloff>:/icons/zoom_out</iconset>

+ 66 - 2
ui/GradientMenu.ui

@@ -69,7 +69,69 @@
     </layout>
    </item>
    <item>
-    <widget class="GradientWidget" name="gradientWidget" native="true"/>
+    <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0">
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <widget class="QPushButton" name="zoomOutBtn">
+         <property name="icon">
+          <iconset resource="../resources/Almond.qrc">
+           <normaloff>:/icons/zoom_out</normaloff>:/icons/zoom_out</iconset>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="zoomInBtn">
+         <property name="icon">
+          <iconset resource="../resources/Almond.qrc">
+           <normaloff>:/icons/zoom_in</normaloff>:/icons/zoom_in</iconset>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QScrollArea" name="scrollArea">
+       <property name="verticalScrollBarPolicy">
+        <enum>Qt::ScrollBarAlwaysOn</enum>
+       </property>
+       <property name="sizeAdjustPolicy">
+        <enum>QAbstractScrollArea::AdjustToContents</enum>
+       </property>
+       <property name="widgetResizable">
+        <bool>true</bool>
+       </property>
+       <widget class="QWidget" name="scrollAreaWidgetContents">
+        <property name="geometry">
+         <rect>
+          <x>0</x>
+          <y>0</y>
+          <width>245</width>
+          <height>359</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>
+         </item>
+        </layout>
+       </widget>
+      </widget>
+     </item>
+    </layout>
    </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -119,6 +181,8 @@
    <container>1</container>
   </customwidget>
  </customwidgets>
- <resources/>
+ <resources>
+  <include location="../resources/Almond.qrc"/>
+ </resources>
  <connections/>
 </ui>