Browse Source

refine QFormLayout policy for VSearcher on macOS

Le Tan 7 years ago
parent
commit
f8717465c3
3 changed files with 19 additions and 2 deletions
  1. 13 0
      src/utils/vutils.cpp
  2. 4 0
      src/utils/vutils.h
  3. 2 2
      src/vsearcher.cpp

+ 13 - 0
src/utils/vutils.cpp

@@ -26,6 +26,7 @@
 #include <QWebEngineView>
 #include <QAction>
 #include <QTreeWidgetItem>
+#include <QFormLayout>
 
 #include "vorphanfile.h"
 #include "vnote.h"
@@ -1514,3 +1515,15 @@ QPixmap VUtils::pixmapFromFile(const QString &p_filePath)
     qDebug() << "pixmapFromFile" << p_filePath << pixmap.isNull();
     return pixmap;
 }
+
+QFormLayout *VUtils::getFormLayout()
+{
+    QFormLayout *layout = new QFormLayout();
+
+#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
+    layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
+    layout->setFormAlignment(Qt::AlignLeft | Qt::AlignTop);
+#endif
+
+    return layout;
+}

+ 4 - 0
src/utils/vutils.h

@@ -20,6 +20,7 @@ class QComboBox;
 class QWebEngineView;
 class QAction;
 class QTreeWidgetItem;
+class QFormLayout;
 
 #if !defined(V_ASSERT)
     #define V_ASSERT(cond) ((!(cond)) ? qt_assert(#cond, __FILE__, __LINE__) : qt_noop())
@@ -327,6 +328,9 @@ public:
 
     static QPixmap pixmapFromFile(const QString &p_filePath);
 
+    // Return QFormLayout.
+    static QFormLayout *getFormLayout();
+
     // Regular expression for image link.
     // ![image title]( http://github.com/tamlok/vnote.jpg "alt text" =200x100)
     // Captured texts (need to be trimmed):

+ 2 - 2
src/vsearcher.cpp

@@ -171,7 +171,7 @@ void VSearcher::setupUI()
                 m_fuzzyCB->setEnabled(!checked);
             });
 
-    QFormLayout *advLayout = new QFormLayout();
+    QFormLayout *advLayout = VUtils::getFormLayout();
     advLayout->addRow(tr("File pattern:"), m_filePatternCB);
     advLayout->addRow(tr("Engine:"), m_searchEngineCB);
     advLayout->addRow(m_caseSensitiveCB);
@@ -226,7 +226,7 @@ void VSearcher::setupUI()
                 updateNumLabel(p_count);
             });
 
-    QFormLayout *formLayout = new QFormLayout();
+    QFormLayout *formLayout = VUtils::getFormLayout();
     formLayout->addRow(tr("Keywords:"), m_keywordCB);
     formLayout->addRow(tr("Scope:"), m_searchScopeCB);
     formLayout->addRow(tr("Object:"), m_searchObjectCB);