mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-17 01:09:36 -06:00
Application: Move DB4SProxyStyle to the Application unit.
Set default maximum icon size for QToolBar to 20px, and for MenuItem to 16px, before that MenuItem icon was bigger than QToolBar icon. Pixel metric for SmallIconSize is set to 12px to avoid strange render behaviour for QDockWidget with custom stylesheet.
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <QDebug>
|
||||
#include <QAction>
|
||||
#include <QFileInfo>
|
||||
#include <QProxyStyle>
|
||||
#include <QStyleOption>
|
||||
|
||||
#include "Application.h"
|
||||
#include "MainWindow.h"
|
||||
@@ -15,6 +17,37 @@
|
||||
#include "version.h"
|
||||
#include "sqlitedb.h"
|
||||
|
||||
class DB4SProxyStyle final : public QProxyStyle {
|
||||
public:
|
||||
DB4SProxyStyle(int toolBarIconSize, int menuItemIconSize, QStyle *style = nullptr)
|
||||
: QProxyStyle(style), m_toolBarIconSize(toolBarIconSize), m_menuItemIconSize(menuItemIconSize) {}
|
||||
|
||||
int pixelMetric(QStyle::PixelMetric metric,
|
||||
const QStyleOption *option = nullptr,
|
||||
const QWidget *widget = nullptr) const override {
|
||||
if (metric == PM_ToolBarIconSize) {
|
||||
return m_toolBarIconSize;
|
||||
} else if (metric == PM_SmallIconSize) {
|
||||
// set maximum icon size for SmallIcon
|
||||
|
||||
// Set default MenuIcon size
|
||||
if(option && option->type == QStyleOption::SO_MenuItem) {
|
||||
return m_menuItemIconSize;
|
||||
}
|
||||
|
||||
// if we don't return size before QDockWidgets are created,
|
||||
// any of the widgets with custom stylesheet are rendered with huge float,close buttons
|
||||
// look void TableBrowserDock::setFocusStyle
|
||||
return 12;
|
||||
}
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_toolBarIconSize;
|
||||
int m_menuItemIconSize;
|
||||
};
|
||||
|
||||
void printArgument(const QString& argument, const QString& description)
|
||||
{
|
||||
const int fieldWidth = 20;
|
||||
@@ -31,12 +64,15 @@ void printArgument(const QString& argument, const QString& description)
|
||||
Application::Application(int& argc, char** argv) :
|
||||
QApplication(argc, argv)
|
||||
{
|
||||
// Set StyleProxy
|
||||
setStyle(new DB4SProxyStyle(20, 16, style()));
|
||||
|
||||
// Get 'DB4S_SETTINGS_FILE' environment variable
|
||||
const char* env = getenv("DB4S_SETTINGS_FILE");
|
||||
const auto env = qgetenv("DB4S_SETTINGS_FILE");
|
||||
|
||||
// If 'DB4S_SETTINGS_FILE' environment variable exists
|
||||
if(env)
|
||||
Settings::setUserSettingsFile(QString::fromStdString(env));
|
||||
if(!env.isEmpty())
|
||||
Settings::setUserSettingsFile(env);
|
||||
|
||||
for(int i=1;i<arguments().size();i++)
|
||||
{
|
||||
@@ -44,10 +80,10 @@ Application::Application(int& argc, char** argv) :
|
||||
{
|
||||
if(++i < arguments().size())
|
||||
{
|
||||
if(env)
|
||||
if(!env.isEmpty())
|
||||
{
|
||||
qWarning() << qPrintable(tr("The user settings file location is replaced with the argument value instead of the environment variable value."));
|
||||
qWarning() << qPrintable(tr("Ignored environment variable(DB4S_SETTINGS_FILE) value : ") + QString::fromStdString(env));
|
||||
qWarning() << qPrintable(tr("Ignored environment variable(DB4S_SETTINGS_FILE) value : ") + env);
|
||||
}
|
||||
Settings::setUserSettingsFile(arguments().at(i));
|
||||
}
|
||||
|
||||
31
src/main.cpp
31
src/main.cpp
@@ -2,7 +2,6 @@
|
||||
#include "Application.h"
|
||||
#include "sqlite.h"
|
||||
#include <QMessageBox>
|
||||
#include <QProxyStyle>
|
||||
|
||||
static QString message = QString();
|
||||
|
||||
@@ -28,36 +27,15 @@ void boxMessageOutput(QtMsgType, const QMessageLogContext &, const QString &msg)
|
||||
message += msg + "\n";
|
||||
}
|
||||
|
||||
class DB4SProxyStyle final : public QProxyStyle {
|
||||
public:
|
||||
DB4SProxyStyle(int toolBarIconSize)
|
||||
: QProxyStyle(nullptr), toolBarIconSize_(toolBarIconSize) {}
|
||||
|
||||
int pixelMetric(QStyle::PixelMetric metric,
|
||||
const QStyleOption *option = nullptr,
|
||||
const QWidget *widget = nullptr) const override {
|
||||
|
||||
if (metric == QStyle::PM_ToolBarIconSize) {
|
||||
return toolBarIconSize_;
|
||||
}
|
||||
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
}
|
||||
|
||||
private:
|
||||
int toolBarIconSize_;
|
||||
};
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
#endif
|
||||
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
#ifdef Q_OS_WIN
|
||||
// In Windows, there is no output to terminal for a graphical application, so we install
|
||||
// the output to message box, until the main window is shown or the application exits.
|
||||
@@ -67,9 +45,6 @@ int main( int argc, char ** argv )
|
||||
// Create application object. All the initialisation stuff happens in there
|
||||
Application a(argc, argv);
|
||||
|
||||
// Set default QToolbar->iconSize via StyleProxy
|
||||
a.setStyle(new DB4SProxyStyle(16));
|
||||
|
||||
// If there has been invocations to the message handler, show it to user in a message box.
|
||||
if(!message.isEmpty()) {
|
||||
QMessageBox messageBox;
|
||||
|
||||
Reference in New Issue
Block a user