From 3aaea23545bc3dd0adc7dada1d60e79c66ed4efc Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 25 Oct 2018 20:18:28 +0800 Subject: [PATCH] fix combo box style on macOS --- src/dialog/vexportdialog.cpp | 4 ++++ src/src.pro | 6 ++++-- src/utils/vutils.cpp | 3 ++- src/utils/vvim.cpp | 11 ++++++++++- src/utils/vvim.h | 2 ++ src/vplantumlhelper.cpp | 2 ++ src/widgets/vcombobox.cpp | 25 +++++++++++++++++++++++++ src/widgets/vcombobox.h | 16 ++++++++++++++++ 8 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/widgets/vcombobox.cpp create mode 100644 src/widgets/vcombobox.h diff --git a/src/dialog/vexportdialog.cpp b/src/dialog/vexportdialog.cpp index 0d1c0b5f..9c782fd7 100644 --- a/src/dialog/vexportdialog.cpp +++ b/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) diff --git a/src/src.pro b/src/src.pro index 3c9c5084..c7e3d73b 100644 --- a/src/src.pro +++ b/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 \ diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 43043988..16acc43a 100644 --- a/src/utils/vutils.cpp +++ b/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); diff --git a/src/utils/vvim.cpp b/src/utils/vvim.cpp index 070dbcb6..b76dea9b 100644 --- a/src/utils/vvim.cpp +++ b/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; +} diff --git a/src/utils/vvim.h b/src/utils/vvim.h index 8ce60f69..e503bd4c 100644 --- a/src/utils/vvim.h +++ b/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; diff --git a/src/vplantumlhelper.cpp b/src/vplantumlhelper.cpp index 56309c33..84c43855 100644 --- a/src/vplantumlhelper.cpp +++ b/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()) { diff --git a/src/widgets/vcombobox.cpp b/src/widgets/vcombobox.cpp new file mode 100644 index 00000000..f36cbea8 --- /dev/null +++ b/src/widgets/vcombobox.cpp @@ -0,0 +1,25 @@ +#include "vcombobox.h" + +#include +#include + +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 +} diff --git a/src/widgets/vcombobox.h b/src/widgets/vcombobox.h new file mode 100644 index 00000000..3a0c5f7d --- /dev/null +++ b/src/widgets/vcombobox.h @@ -0,0 +1,16 @@ +#ifndef VCOMBOBOX_H +#define VCOMBOBOX_H + +#include + + +class VComboBox : public QComboBox +{ + Q_OBJECT +public: + explicit VComboBox(QWidget *p_parent = nullptr); + + void showPopup() Q_DECL_OVERRIDE; +}; + +#endif // VCOMBOBOX_H