Jelajahi Sumber

fix combo box style on macOS

Le Tan 7 tahun lalu
induk
melakukan
3aaea23545

+ 4 - 0
src/dialog/vexportdialog.cpp

@@ -1252,6 +1252,10 @@ void VExportDialog::handleCurrentFormatChanged(int p_index)
 
     m_wkTitleEdit->setEnabled(pdfTitleNameEnabled);
     m_wkTargetFileNameEdit->setEnabled(pdfTitleNameEnabled);
+
+    QTimer::singleShot(100, [this]() {
+                resize(size().width(), minimumSizeHint().height());
+            });
 }
 
 void VExportDialog::handleCurrentSrcChanged(int p_index)

+ 4 - 2
src/src.pro

@@ -149,7 +149,8 @@ SOURCES += main.cpp\
     vtexteditcompleter.cpp \
     utils/vkeyboardlayoutmanager.cpp \
     dialog/vkeyboardlayoutmappingdialog.cpp \
-    vfilelistwidget.cpp
+    vfilelistwidget.cpp \
+    widgets/vcombobox.cpp
 
 HEADERS  += vmainwindow.h \
     vdirectorytree.h \
@@ -291,7 +292,8 @@ HEADERS  += vmainwindow.h \
     vtextdocumentlayoutdata.h \
     utils/vkeyboardlayoutmanager.h \
     dialog/vkeyboardlayoutmappingdialog.h \
-    vfilelistwidget.h
+    vfilelistwidget.h \
+    widgets/vcombobox.h
 
 RESOURCES += \
     vnote.qrc \

+ 2 - 1
src/utils/vutils.cpp

@@ -38,6 +38,7 @@
 #include "vnotebook.h"
 #include "vpreviewpage.h"
 #include "pegparser.h"
+#include "widgets/vcombobox.h"
 
 extern VConfigManager *g_config;
 
@@ -1403,7 +1404,7 @@ bool VUtils::isMetaKey(int p_key)
 
 QComboBox *VUtils::getComboBox(QWidget *p_parent)
 {
-    QComboBox *box = new QComboBox(p_parent);
+    QComboBox *box = new VComboBox(p_parent);
     QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(box);
     box->setItemDelegate(itemDelegate);
 

+ 10 - 1
src/utils/vvim.cpp

@@ -617,7 +617,7 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
     }
 
     // Ctrl and Shift may be sent out first.
-    if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta) {
+    if (isKeyShouldBeIgnored(key)) {
         goto accept;
     }
 
@@ -6483,3 +6483,12 @@ void VVim::clearSelectionAndEnterNormalMode()
 
     setMode(VimMode::Normal, true, position);
 }
+
+bool VVim::isKeyShouldBeIgnored(int p_key) const
+{
+    if (VUtils::isMetaKey(p_key)) {
+        return true;
+    }
+
+    return false;
+}

+ 2 - 0
src/utils/vvim.h

@@ -838,6 +838,8 @@ private:
 
     void clearSelectionAndEnterNormalMode();
 
+    bool isKeyShouldBeIgnored(int p_key) const;
+
     VEditor *m_editor;
     const VEditConfig *m_editConfig;
     VimMode m_mode;

+ 2 - 0
src/vplantumlhelper.cpp

@@ -70,8 +70,10 @@ void VPlantUMLHelper::prepareCommand(QString &p_program,
     p_args << "-jar" << (p_jar.isEmpty() ? g_config->getPlantUMLJar() : p_jar);
     p_args << "-charset" << "UTF-8";
 
+    /*
     int nbthread = QThread::idealThreadCount();
     p_args << "-nbthread" << QString::number(nbthread > 0 ? nbthread : 1);
+    */
 
     const QString &dot = g_config->getGraphvizDot();
     if (!dot.isEmpty()) {

+ 25 - 0
src/widgets/vcombobox.cpp

@@ -0,0 +1,25 @@
+#include "vcombobox.h"
+
+#include <QAbstractItemModel>
+#include <QAbstractItemView>
+
+VComboBox::VComboBox(QWidget *p_parent)
+    : QComboBox(p_parent)
+{
+}
+
+void VComboBox::showPopup()
+{
+    QComboBox::showPopup();
+
+#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
+    auto *vw = view();
+    if (count() > 0) {
+        int cnt = qMin(count(), maxVisibleItems());
+        int height = 20 + cnt * vw->visualRect(vw->model()->index(0, 0)).height();
+        if (height > vw->height()) {
+            vw->setMinimumHeight(height);
+        }
+    }
+#endif
+}

+ 16 - 0
src/widgets/vcombobox.h

@@ -0,0 +1,16 @@
+#ifndef VCOMBOBOX_H
+#define VCOMBOBOX_H
+
+#include <QComboBox>
+
+
+class VComboBox : public QComboBox
+{
+    Q_OBJECT
+public:
+    explicit VComboBox(QWidget *p_parent = nullptr);
+
+    void showPopup() Q_DECL_OVERRIDE;
+};
+
+#endif // VCOMBOBOX_H