fix combo box style on macOS

This commit is contained in:
Le Tan 2018-10-25 20:18:28 +08:00
parent 493ba08bd0
commit 3aaea23545
8 changed files with 65 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

25
src/widgets/vcombobox.cpp Normal file
View File

@ -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
src/widgets/vcombobox.h Normal file
View File

@ -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