2
0
forked from Ivasoft/DSView

restore the dscombobox for mac

This commit is contained in:
dreamsourcelabTAI
2024-04-08 16:31:51 +08:00
parent 5dbc223e53
commit 62eec1b80f
4 changed files with 46 additions and 62 deletions

View File

@@ -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("-");

View File

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

View File

@@ -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 <QFontMetrics>
#include <QString>
#include <QGuiApplication>
#include <QScreen>
#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<QFrame*>();
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;
}
*/
}
void DsComboBox::hidePopup()
{
QComboBox::hidePopup();
_bPopup = false;
}

View File

@@ -25,20 +25,14 @@
#include <QComboBox>
#include <QKeyEvent>
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