From 62eec1b80f4f3cb2b2c767b2266407c3450ee4b1 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Mon, 8 Apr 2024 16:31:51 +0800 Subject: [PATCH] restore the dscombobox for mac --- DSView/pv/dialogs/storeprogress.cpp | 10 ++-- DSView/pv/toolbars/logobar.cpp | 3 +- DSView/pv/ui/dscombobox.cpp | 84 +++++++++++++---------------- DSView/pv/ui/dscombobox.h | 11 +--- 4 files changed, 46 insertions(+), 62 deletions(-) diff --git a/DSView/pv/dialogs/storeprogress.cpp b/DSView/pv/dialogs/storeprogress.cpp index 285333b0..60ac4eaa 100644 --- a/DSView/pv/dialogs/storeprogress.cpp +++ b/DSView/pv/dialogs/storeprogress.cpp @@ -36,8 +36,8 @@ #include "../log.h" #include "../view/view.h" #include "../view/cursor.h" - #include "../ui/langresource.h" +#include "../ui/dscombobox.h" namespace pv { namespace dialogs { @@ -278,8 +278,8 @@ void StoreProgress::save_run(ISessionDataGetter *getter) { QFormLayout *lay = new QFormLayout(); lay->setContentsMargins(5, 0, 0, 0); - _start_cursor = new QComboBox(); - _end_cursor = new QComboBox(); + _start_cursor = new DsComboBox(); + _end_cursor = new DsComboBox(); _start_cursor->addItem("-"); _end_cursor->addItem("-"); @@ -318,8 +318,8 @@ void StoreProgress::export_run() _ckCompress->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_COMPRESSED_DATA), "Compressed data")); _ckCompress->setChecked(!isOrg); - _start_cursor = new QComboBox(); - _end_cursor = new QComboBox(); + _start_cursor = new DsComboBox(); + _end_cursor = new DsComboBox(); _start_cursor->addItem("-"); _end_cursor->addItem("-"); diff --git a/DSView/pv/toolbars/logobar.cpp b/DSView/pv/toolbars/logobar.cpp index 3e3f6062..8794276a 100644 --- a/DSView/pv/toolbars/logobar.cpp +++ b/DSView/pv/toolbars/logobar.cpp @@ -47,6 +47,7 @@ #include "../ui/langresource.h" #include "../ui/msgbox.h" #include "../ui/fn.h" +#include "../ui/dscombobox.h" namespace pv { namespace toolbars { @@ -239,7 +240,7 @@ void LogoBar::on_action_setting_log() panel->setLayout(lay); lay->setVerticalSpacing(15); - QComboBox *cbBox = new QComboBox(); + QComboBox *cbBox = new DsComboBox(); cbBox->setMinimumWidth(40); lay->addRow(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_LOG_LEVEL), "Log Level"), cbBox); diff --git a/DSView/pv/ui/dscombobox.cpp b/DSView/pv/ui/dscombobox.cpp index 62a5238d..a7508ef5 100644 --- a/DSView/pv/ui/dscombobox.cpp +++ b/DSView/pv/ui/dscombobox.cpp @@ -19,85 +19,75 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -#include "dscombobox.h" - -DsComboBox::DsComboBox(QWidget *parent) - : QComboBox(parent) -{ -} - -/* #include "dscombobox.h" #include #include #include #include - #include "../config/appconfig.h" -DsComboBox::DsComboBox(QWidget *parent) : QComboBox(parent) +DsComboBox::DsComboBox(QWidget *parent) + :QComboBox(parent) { _contentWidth = 0; _bPopup = false; QComboBox::setSizeAdjustPolicy(QComboBox::AdjustToContents); } + +DsComboBox::~DsComboBox() +{ + +} - void DsComboBox::addItem(const QString &atext, const QVariant &auserData) - { - QComboBox::addItem(atext, auserData); +void DsComboBox::addItem(const QString &atext, const QVariant &auserData) +{ + QComboBox::addItem(atext, auserData); #ifdef Q_OS_DARWIN - if (!atext.isEmpty()){ - QFontMetrics fm = this->fontMetrics(); - int w = fm.boundingRect(atext).width(); - if (w > _contentWidth){ - _contentWidth = w; - this->setStyleSheet("QAbstractItemView{min-width:" + QString::number(w + 30) + "px;}"); - } - } + if (!atext.isEmpty()){ + QFontMetrics fm = this->fontMetrics(); + int w = fm.boundingRect(atext).width(); + if (w > _contentWidth){ + _contentWidth = w; + this->setStyleSheet("QAbstractItemView{min-width:" + QString::number(w + 30) + "px;}"); + } + } #endif - } +} - void DsComboBox::showPopup() - { - QComboBox::showPopup(); +void DsComboBox::showPopup() +{ + QComboBox::showPopup(); _bPopup = true; +#ifdef Q_OS_DARWIN + QWidget *popup = this->findChild(); auto rc = popup->geometry(); - int x = rc.left(); + int x = rc.left() + 6; int y = rc.top(); - int w = rc.right() - rc.left() + 2; + int w = rc.right() - rc.left(); int h = rc.bottom() - rc.top() + 20; - -#ifdef Q_OS_DARWIN - x += 6; -#endif - -#ifndef _WIN32 - w += 3; -#endif - popup->setGeometry(x, y, w, h); int sy = QGuiApplication::primaryScreen()->size().height(); if (sy <= 1080){ popup->setMaximumHeight(750); } - - if (AppConfig::Instance().frameOptions.style == THEME_STYLE_DARK){ + + if (AppConfig::Instance().IsDarkStyle()){ popup->setStyleSheet("background-color:#262626;"); } else{ popup->setStyleSheet("background-color:#white;"); } - } +#endif - void DsComboBox::hidePopup() - { - QComboBox::hidePopup(); - _bPopup = false; - } - -*/ \ No newline at end of file +} + +void DsComboBox::hidePopup() +{ + QComboBox::hidePopup(); + _bPopup = false; +} + \ No newline at end of file diff --git a/DSView/pv/ui/dscombobox.h b/DSView/pv/ui/dscombobox.h index 96ed5219..d6edf405 100644 --- a/DSView/pv/ui/dscombobox.h +++ b/DSView/pv/ui/dscombobox.h @@ -25,20 +25,14 @@ #include #include -class DsComboBox : public QComboBox -{ -public: - explicit DsComboBox(QWidget *parent = nullptr); -}; -/* class DsComboBox : public QComboBox { - Q_OBJECT - public: explicit DsComboBox(QWidget *parent = nullptr); + ~DsComboBox(); + void addItem(const QString &atext, const QVariant &userData = QVariant()); public: @@ -54,7 +48,6 @@ private: int _contentWidth; bool _bPopup; }; -*/ #endif // DSCOMBOBOX_H