Skip to content

Commit 3ba4e53

Browse files
committed
fix(export): fix source combo item selection and buffer content in read mode
Replace Qt::UserRole-1 (Qt::StandardItemFlagsRole) with proper QStandardItem::setEnabled() for disabling unavailable export sources. The previous approach accidentally overwrote item flags, making all source combo items unselectable. Also fix getLatestContent() in MarkdownViewWindow2 and TextViewWindow2 to fall back to Buffer2::getContentRaw() when the editor widget is null (read/preview mode), so the 'Current Buffer' export source is available regardless of view mode. Add explicit text color to QComboBox popup items across all theme QSS files to prevent grey fallback when inside QGroupBox.
1 parent ff93ab4 commit 3ba4e53

11 files changed

Lines changed: 167 additions & 126 deletions

File tree

src/data/extra/themes/moonlight/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,14 @@ QComboBox QAbstractItemView {
409409
padding: 2px;
410410
border: 1px solid @widgets#qcombobox#view#border;
411411
background-color: @widgets#qcombobox#view#bg;
412+
color: @widgets#qcombobox#fg;
412413
selection-color: @widgets#qcombobox#view#selection#fg;
413414
selection-background-color: @widgets#qcombobox#view#selection#bg;
414415
}
415416

416417
QComboBox QAbstractItemView::item {
417418
background-color: transparent;
419+
color: @widgets#qcombobox#fg;
418420
padding: 3px;
419421
}
420422

src/data/extra/themes/pure/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,14 @@ QComboBox QAbstractItemView {
548548
border: 1px solid @widgets#qcombobox#view#border;
549549
border-radius: 4px;
550550
background-color: @widgets#qcombobox#view#bg;
551+
color: @widgets#qcombobox#fg;
551552
selection-color: @widgets#qcombobox#view#selection#fg;
552553
selection-background-color: @widgets#qcombobox#view#selection#bg;
553554
}
554555

555556
QComboBox QAbstractItemView::item {
556557
background-color: transparent;
558+
color: @widgets#qcombobox#fg;
557559
padding: 4px 8px;
558560
}
559561

src/data/extra/themes/solarized-dark/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,14 @@ QComboBox QAbstractItemView {
405405
padding: 2px;
406406
border: 1px solid @widgets#qcombobox#view#border;
407407
background-color: @widgets#qcombobox#view#bg;
408+
color: @widgets#qcombobox#fg;
408409
selection-color: @widgets#qcombobox#view#selection#fg;
409410
selection-background-color: @widgets#qcombobox#view#selection#bg;
410411
}
411412

412413
QComboBox QAbstractItemView::item {
413414
background-color: transparent;
415+
color: @widgets#qcombobox#fg;
414416
padding: 3px;
415417
}
416418

src/data/extra/themes/solarized-light/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,14 @@ QComboBox QAbstractItemView {
405405
padding: 2px;
406406
border: 1px solid @widgets#qcombobox#view#border;
407407
background-color: @widgets#qcombobox#view#bg;
408+
color: @widgets#qcombobox#fg;
408409
selection-color: @widgets#qcombobox#view#selection#fg;
409410
selection-background-color: @widgets#qcombobox#view#selection#bg;
410411
}
411412

412413
QComboBox QAbstractItemView::item {
413414
background-color: transparent;
415+
color: @widgets#qcombobox#fg;
414416
padding: 3px;
415417
}
416418

src/data/extra/themes/vscode-dark/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,14 @@ QComboBox QAbstractItemView {
405405
padding: 2px;
406406
border: 1px solid @widgets#qcombobox#view#border;
407407
background-color: @widgets#qcombobox#view#bg;
408+
color: @widgets#qcombobox#fg;
408409
selection-color: @widgets#qcombobox#view#selection#fg;
409410
selection-background-color: @widgets#qcombobox#view#selection#bg;
410411
}
411412

412413
QComboBox QAbstractItemView::item {
413414
background-color: transparent;
415+
color: @widgets#qcombobox#fg;
414416
padding: 3px;
415417
}
416418

src/data/extra/themes/vue-dark/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,14 @@ QComboBox QAbstractItemView {
410410
padding: 2px;
411411
border: 1px solid @widgets#qcombobox#view#border;
412412
background-color: @widgets#qcombobox#view#bg;
413+
color: @widgets#qcombobox#fg;
413414
selection-color: @widgets#qcombobox#view#selection#fg;
414415
selection-background-color: @widgets#qcombobox#view#selection#bg;
415416
}
416417

417418
QComboBox QAbstractItemView::item {
418419
background-color: transparent;
420+
color: @widgets#qcombobox#fg;
419421
padding: 3px;
420422
}
421423

src/data/extra/themes/vue-light/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,14 @@ QComboBox QAbstractItemView {
424424
padding: 2px;
425425
border: 1px solid @widgets#qcombobox#view#border;
426426
background-color: @widgets#qcombobox#view#bg;
427+
color: @widgets#qcombobox#fg;
427428
selection-color: @widgets#qcombobox#view#selection#fg;
428429
selection-background-color: @widgets#qcombobox#view#selection#bg;
429430
}
430431

431432
QComboBox QAbstractItemView::item {
432433
background-color: transparent;
434+
color: @widgets#qcombobox#fg;
433435
padding: 3px;
434436
}
435437

src/data/extra/themes/vx-idea/interface.qss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,14 @@ QComboBox QAbstractItemView {
424424
padding: 2px;
425425
border: 1px solid @widgets#qcombobox#view#border;
426426
background-color: @widgets#qcombobox#view#bg;
427+
color: @widgets#qcombobox#fg;
427428
selection-color: @widgets#qcombobox#view#selection#fg;
428429
selection-background-color: @widgets#qcombobox#view#selection#bg;
429430
}
430431

431432
QComboBox QAbstractItemView::item {
432433
background-color: transparent;
434+
color: @widgets#qcombobox#fg;
433435
padding: 3px;
434436
}
435437

src/widgets/dialogs/exportdialog2.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QProgressBar>
2020
#include <QPushButton>
2121
#include <QStackedLayout>
22+
#include <QStandardItemModel>
2223
#include <QTextCursor>
2324
#include <QUrl>
2425
#include <QVBoxLayout>
@@ -209,11 +210,15 @@ void ExportDialog2::setupUI() {
209210
auto source = static_cast<ExportSource>(i);
210211
m_sourceCombo->addItem(sourceText(source, m_context), i);
211212
const int idx = m_sourceCombo->count() - 1;
212-
auto item = m_sourceCombo->model()->index(idx, 0);
213-
m_sourceCombo->model()->setData(item, 1, Qt::UserRole - 1);
214213

215214
if (!sourceAvailable(source, m_context)) {
216-
m_sourceCombo->model()->setData(item, 0, Qt::UserRole - 1);
215+
// Disable the item via QStandardItem flags (the proper Qt API).
216+
auto *stdModel = qobject_cast<QStandardItemModel *>(m_sourceCombo->model());
217+
if (stdModel) {
218+
if (auto *stdItem = stdModel->item(idx)) {
219+
stdItem->setEnabled(false);
220+
}
221+
}
217222
m_sourceCombo->setItemData(idx, sourceUnavailableReason(source), Qt::ToolTipRole);
218223
}
219224
}
@@ -475,10 +480,9 @@ void ExportDialog2::loadConfig() {
475480
restoreFields(option);
476481

477482
const int presetIdx = m_sourceCombo->findData(static_cast<int>(m_context.presetSource));
478-
if (presetIdx >= 0 &&
479-
m_sourceCombo->model()
480-
->data(m_sourceCombo->model()->index(presetIdx, 0), Qt::UserRole - 1)
481-
.toInt() == 1) {
483+
if (presetIdx >= 0 && m_sourceCombo->model()
484+
->flags(m_sourceCombo->model()->index(presetIdx, 0))
485+
.testFlag(Qt::ItemIsEnabled)) {
482486
m_sourceCombo->setCurrentIndex(presetIdx);
483487
}
484488
}
@@ -491,8 +495,8 @@ void ExportDialog2::saveConfig() {
491495
void ExportDialog2::restoreFields(const ExportOption &p_option) {
492496
int idx = m_sourceCombo->findData(static_cast<int>(p_option.m_source));
493497
if (idx >= 0 && m_sourceCombo->model()
494-
->data(m_sourceCombo->model()->index(idx, 0), Qt::UserRole - 1)
495-
.toInt() == 1) {
498+
->flags(m_sourceCombo->model()->index(idx, 0))
499+
.testFlag(Qt::ItemIsEnabled)) {
496500
m_sourceCombo->setCurrentIndex(idx);
497501
}
498502

0 commit comments

Comments
 (0)