mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-02 02:16:53 +01:00
Issue #200: Icons under dark theme on Arch/KDE is broken
This commit is contained in:
parent
e841836b99
commit
c1fd0cdd4a
@ -58,15 +58,7 @@ int main(int argc, char *argv[])
|
||||
pdf::PDFSecurityHandler::setNoDRMMode();
|
||||
}
|
||||
|
||||
if (parser.isSet(lightGui))
|
||||
{
|
||||
pdf::PDFWidgetUtils::setDarkTheme(false);
|
||||
}
|
||||
|
||||
if (parser.isSet(darkGui))
|
||||
{
|
||||
pdf::PDFWidgetUtils::setDarkTheme(true);
|
||||
}
|
||||
pdf::PDFWidgetUtils::setDarkTheme(parser.isSet(lightGui), parser.isSet(darkGui));
|
||||
|
||||
QIcon appIcon(":/app-icon.svg");
|
||||
QApplication::setWindowIcon(appIcon);
|
||||
|
@ -187,6 +187,17 @@ PDFSidebarWidget::PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy,
|
||||
ui->signatureTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->signatureTreeWidget, &QTreeWidget::customContextMenuRequested, this, &PDFSidebarWidget::onSignatureCustomContextMenuRequested);
|
||||
|
||||
if (pdf::PDFWidgetUtils::isDarkTheme())
|
||||
{
|
||||
for (QToolButton* pushButton : findChildren<QToolButton*>())
|
||||
{
|
||||
QIcon icon = pushButton->icon();
|
||||
QSize iconSize = pushButton->iconSize();
|
||||
QIcon iconDark = pdf::PDFWidgetUtils::convertIconForDarkTheme(icon, iconSize, pushButton->devicePixelRatioF());
|
||||
pushButton->setIcon(iconDark);
|
||||
}
|
||||
}
|
||||
|
||||
selectPage(Invalid);
|
||||
updateButtons();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "pdfdocument.h"
|
||||
#include "pdfdrawspacecontroller.h"
|
||||
#include "pdfdrawwidget.h"
|
||||
#include "pdfwidgetutils.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QStyle>
|
||||
@ -381,7 +382,14 @@ QVariant PDFOutlineTreeItemModel::data(const QModelIndex& index, int role) const
|
||||
return outlineItem->getTitle();
|
||||
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
// We do not set item color if the dark theme is set
|
||||
if (pdf::PDFWidgetUtils::isDarkTheme())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
return QBrush(outlineItem->getTextColor());
|
||||
}
|
||||
|
||||
case Qt::FontRole:
|
||||
{
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QApplication>
|
||||
#include <QStyleHints>
|
||||
#include <QStyleFactory>
|
||||
|
||||
#include "pdfdbgheap.h"
|
||||
|
||||
@ -174,9 +175,81 @@ void PDFWidgetUtils::style(QWidget* widget)
|
||||
}
|
||||
}
|
||||
|
||||
void PDFWidgetUtils::setDarkTheme(bool isDarkTheme)
|
||||
void PDFWidgetUtils::setDarkTheme(bool isLightTheme, bool isDarkTheme)
|
||||
{
|
||||
QApplication::styleHints()->setColorScheme(isDarkTheme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light);
|
||||
if (isLightTheme)
|
||||
{
|
||||
QApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light);
|
||||
}
|
||||
|
||||
if (isDarkTheme)
|
||||
{
|
||||
QApplication::styleHints()->setColorScheme(Qt::ColorScheme::Dark);
|
||||
}
|
||||
|
||||
if (PDFWidgetUtils::isDarkTheme())
|
||||
{
|
||||
QPalette darkPalette = QApplication::palette();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||
|
||||
// Basic colors
|
||||
darkPalette.setColor(QPalette::WindowText, QColor(220, 220, 220));
|
||||
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::Light, QColor(70, 70, 70));
|
||||
darkPalette.setColor(QPalette::Midlight, QColor(60, 60, 60));
|
||||
darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35));
|
||||
darkPalette.setColor(QPalette::Mid, QColor(40, 40, 40));
|
||||
|
||||
// Texts
|
||||
darkPalette.setColor(QPalette::Text, QColor(220, 220, 220));
|
||||
darkPalette.setColor(QPalette::BrightText, Qt::red);
|
||||
darkPalette.setColor(QPalette::ButtonText, QColor(220, 220, 220));
|
||||
|
||||
// Background
|
||||
darkPalette.setColor(QPalette::Base, QColor(42, 42, 42));
|
||||
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20));
|
||||
|
||||
// Highlight
|
||||
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); // Barva výběru
|
||||
darkPalette.setColor(QPalette::HighlightedText, Qt::black); // Text ve výběru
|
||||
|
||||
// Links
|
||||
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); // Odkazy
|
||||
darkPalette.setColor(QPalette::LinkVisited, QColor(100, 100, 150)); // Navštívené odkazy
|
||||
|
||||
// Alternative background
|
||||
darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); // Např. střídavé řádky v tabulce
|
||||
|
||||
// Special roles
|
||||
darkPalette.setColor(QPalette::NoRole, QColor(0, 0, 0, 0));
|
||||
|
||||
// Help
|
||||
darkPalette.setColor(QPalette::ToolTipBase, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::ToolTipText, QColor(220, 220, 220));
|
||||
|
||||
for (int i = 0; i < QPalette::NColorRoles; ++i)
|
||||
{
|
||||
QColor disabledColor = darkPalette.color(QPalette::Disabled, static_cast<QPalette::ColorRole>(i));
|
||||
disabledColor = disabledColor.darker(200);
|
||||
darkPalette.setColor(QPalette::Disabled, static_cast<QPalette::ColorRole>(i), disabledColor);
|
||||
|
||||
QColor currentColor = darkPalette.color(QPalette::Current, static_cast<QPalette::ColorRole>(i));
|
||||
currentColor = currentColor.lighter(150);
|
||||
darkPalette.setColor(QPalette::Current, static_cast<QPalette::ColorRole>(i), currentColor);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Placeholder text (Qt 5.12+)
|
||||
darkPalette.setColor(QPalette::PlaceholderText, QColor(150, 150, 150));
|
||||
|
||||
// Accents (Qt 6.5+)
|
||||
darkPalette.setColor(QPalette::Accent, QColor(42, 130, 218));
|
||||
|
||||
QApplication::setPalette(darkPalette);
|
||||
}
|
||||
}
|
||||
|
||||
bool PDFWidgetUtils::isDarkTheme()
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
static void style(QWidget* widget);
|
||||
|
||||
/// Overrides automatically detected dark theme / light theme settings
|
||||
static void setDarkTheme(bool isDarkTheme);
|
||||
static void setDarkTheme(bool isLightTheme, bool isDarkTheme);
|
||||
|
||||
/// Returns true if the dark theme is currently set for the application.
|
||||
static bool isDarkTheme();
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "pdfconstants.h"
|
||||
#include "pdfsecurityhandler.h"
|
||||
#include "pdfwidgetutils.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
@ -33,10 +34,14 @@ int main(int argc, char *argv[])
|
||||
QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT PageMaster"));
|
||||
|
||||
QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents.");
|
||||
QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI.");
|
||||
QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI.");
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QCoreApplication::applicationName());
|
||||
parser.addOption(noDrm);
|
||||
parser.addOption(lightGui);
|
||||
parser.addOption(darkGui);
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("file", "The PDF file to open.");
|
||||
@ -47,6 +52,8 @@ int main(int argc, char *argv[])
|
||||
pdf::PDFSecurityHandler::setNoDRMMode();
|
||||
}
|
||||
|
||||
pdf::PDFWidgetUtils::setDarkTheme(parser.isSet(lightGui), parser.isSet(darkGui));
|
||||
|
||||
QIcon appIcon(":/app-icon.svg");
|
||||
QApplication::setWindowIcon(appIcon);
|
||||
|
||||
|
@ -87,6 +87,7 @@ void PageItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opti
|
||||
QRect textRect = option.rect;
|
||||
textRect.setTop(textOffset);
|
||||
textRect.setHeight(option.fontMetrics.lineSpacing());
|
||||
painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text));
|
||||
painter->drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, item->groupName);
|
||||
textRect.translate(0, textRect.height());
|
||||
painter->drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, item->pagesCaption);
|
||||
|
@ -52,15 +52,7 @@ int main(int argc, char *argv[])
|
||||
pdf::PDFSecurityHandler::setNoDRMMode();
|
||||
}
|
||||
|
||||
if (parser.isSet(lightGui))
|
||||
{
|
||||
pdf::PDFWidgetUtils::setDarkTheme(false);
|
||||
}
|
||||
|
||||
if (parser.isSet(darkGui))
|
||||
{
|
||||
pdf::PDFWidgetUtils::setDarkTheme(true);
|
||||
}
|
||||
pdf::PDFWidgetUtils::setDarkTheme(parser.isSet(lightGui), parser.isSet(darkGui));
|
||||
|
||||
QIcon appIcon(":/app-icon.svg");
|
||||
QApplication::setWindowIcon(appIcon);
|
||||
|
@ -4,6 +4,7 @@ CURRENT:
|
||||
- Issue #206: Name of the executable / command
|
||||
- Issue #205: Editor cannot create white, whitesmoke or transparent annotations
|
||||
- Issue #202: Certain raster content not rendered
|
||||
- Issue #200: Icons under dark theme on Arch/KDE is broken
|
||||
- Issue #185: Latest git fails to build in linux
|
||||
- Issue #165: Insert > Inline Text latency issues on Flatpak and Appimage packages
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user