Browse Source

addFile function for adding files to UI
thumbnails to preview images

logicp 5 years ago
parent
commit
393e8c675f
3 changed files with 86 additions and 28 deletions
  1. 67 27
      argdialog.ui
  2. 1 0
      include/argdialog.h
  3. 18 1
      src/argdialog.cpp

+ 67 - 27
argdialog.ui

@@ -30,7 +30,7 @@ background-color: rgb(0, 43, 54);</string>
      <height>921</height>
     </rect>
    </property>
-   <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,2,0,0,1,0,8,1">
+   <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0,0,0,3,0">
     <item>
      <widget class="QLabel" name="argDialogTitle">
       <property name="font">
@@ -288,35 +288,75 @@ padding-left: 8px;</string>
      </widget>
     </item>
     <item>
-     <widget class="QTableWidget" name="argList">
-      <property name="styleSheet">
-       <string notr="true">font: 87 11pt &quot;Noto Sans&quot;;
+     <layout class="QHBoxLayout" name="horizontalLayout_6" stretch="0,0,0">
+      <item>
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Maximum</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QTableWidget" name="argList">
+        <property name="styleSheet">
+         <string notr="true">font: 87 11pt &quot;Noto Sans&quot;;
 background-color: #2f535f;
 color: rgb(131, 148, 150);
 font-weight: 700;
-</string>
-      </property>
-      <property name="columnCount">
-       <number>2</number>
-      </property>
-      <attribute name="horizontalHeaderCascadingSectionResizes">
-       <bool>false</bool>
-      </attribute>
-      <attribute name="horizontalHeaderMinimumSectionSize">
-       <number>100</number>
-      </attribute>
-      <attribute name="horizontalHeaderDefaultSectionSize">
-       <number>200</number>
-      </attribute>
-      <attribute name="verticalHeaderMinimumSectionSize">
-       <number>100</number>
-      </attribute>
-      <attribute name="verticalHeaderDefaultSectionSize">
-       <number>100</number>
-      </attribute>
-      <column/>
-      <column/>
-     </widget>
+padding-left: 2px;</string>
+        </property>
+        <property name="showGrid">
+         <bool>true</bool>
+        </property>
+        <property name="columnCount">
+         <number>3</number>
+        </property>
+        <attribute name="horizontalHeaderCascadingSectionResizes">
+         <bool>false</bool>
+        </attribute>
+        <attribute name="horizontalHeaderMinimumSectionSize">
+         <number>100</number>
+        </attribute>
+        <attribute name="horizontalHeaderDefaultSectionSize">
+         <number>200</number>
+        </attribute>
+        <attribute name="verticalHeaderMinimumSectionSize">
+         <number>100</number>
+        </attribute>
+        <attribute name="verticalHeaderDefaultSectionSize">
+         <number>100</number>
+        </attribute>
+        <column/>
+        <column/>
+        <column/>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Maximum</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
     </item>
     <item>
      <layout class="QHBoxLayout" name="horizontalLayout_5">

+ 1 - 0
include/argdialog.h

@@ -75,6 +75,7 @@ class ArgDialog : public QDialog {
   void setTaskArguments();
   Ui::ArgDialog *ui;
   void addItem(QString value, QString type);
+  void addFile(QString path);
   Task m_task;
   IGPost m_ig_post;
 };

+ 18 - 1
src/argdialog.cpp

@@ -38,10 +38,14 @@ ArgDialog::ArgDialog(QWidget *parent) :
                 m_ig_post.is_video = true; // rename to "sending_video"
                 QString preview_filename = FileUtils::generatePreview(file_path, file_name);
                 // TODO: create some way of verifying preview generation was successful
+                addFile("assets/previews/" + preview_filename);
                 addItem(preview_filename, "file");
+                addFile("assets/previews/" + preview_filename);
                 m_ig_post.files.push_back(KFile{
                     .name=preview_filename, .path=QCoreApplication::applicationDirPath() + "/assets/previews/" + preview_filename, .type = is_video ? FileType::VIDEO : FileType::IMAGE
                 });
+            } else {
+                addFile(file_path);
             }
         }
     });
@@ -143,7 +147,7 @@ void ArgDialog::setTaskArguments() {
         requested_by += "@" + name + "";
     }
     if (m_ig_post.requested_by.size() > 1) {
-    requested_by.pop_back();
+        requested_by.pop_back();
     }
 
 //    m_task.args.push_back(m_ig_post.file.name.toUtf8().constData());
@@ -166,6 +170,19 @@ void ArgDialog::addItem(QString value, QString type) {
     ui->argList->setItem(row, 1, item2);
 }
 
+void ArgDialog::addFile(QString path) {
+    auto row_count = ui->argList->rowCount();
+
+    QTableWidgetItem* file_item = new QTableWidgetItem();
+    QPixmap pm{path};
+    file_item->setData(
+        Qt::DecorationRole,
+        pm.scaledToHeight(ui->argList->rowHeight(0), Qt::TransformationMode::SmoothTransformation)
+    );
+    ui->argList->setItem(row_count - 1, 2, file_item);
+
+}
+
 void ArgDialog::clearPost() {
     m_ig_post.files.clear();
     m_ig_post.datetime = "";