Skip to content

Commit

Permalink
More styling and use Phantom as base style
Browse files Browse the repository at this point in the history
  • Loading branch information
phoerious committed Jan 6, 2020
1 parent 81a36a6 commit 71e3e0b
Show file tree
Hide file tree
Showing 21 changed files with 6,382 additions and 127 deletions.
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ set(keepassx_SOURCES
format/OpVaultReaderAttachments.cpp
format/OpVaultReaderBandEntry.cpp
format/OpVaultReaderSections.cpp
gui/styles/dark/darkstyle.qrc
gui/styles/dark/KpxcDarkStyle.cpp
gui/styles/styles.qrc
gui/styles/base/BaseStyle.cpp
gui/styles/dark/DarkStyle.cpp
gui/styles/light/LightStyle.cpp
gui/styles/phantomstyle/phantomcolor.cpp
gui/styles/phantomstyle/phantomstyle.cpp
gui/AboutDialog.cpp
gui/Application.cpp
gui/CategoryListWidget.cpp
Expand Down
20 changes: 7 additions & 13 deletions src/gui/ApplicationSettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>684</width>
<height>951</height>
<height>1206</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -57,11 +57,11 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="minimizeAfterUnlockCheckBox">
<property name="text">
<string>Minimize window after unlocking database</string>
</property>
</widget>
<widget class="QCheckBox" name="minimizeAfterUnlockCheckBox">
<property name="text">
<string>Minimize window after unlocking database</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
Expand Down Expand Up @@ -337,7 +337,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,1">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
<item>
<widget class="QLabel" name="faviconTimeoutLabel">
<property name="text">
Expand All @@ -350,12 +350,6 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
Expand Down
18 changes: 6 additions & 12 deletions src/gui/CategoryListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <QListWidget>
#include <QPainter>
#include <QProxyStyle>
#include <QScrollBar>
#include <QSize>
#include <QStyledItemDelegate>
Expand Down Expand Up @@ -158,9 +159,8 @@ CategoryListWidgetDelegate::CategoryListWidgetDelegate(QListWidget* parent)
}
}

#ifdef Q_OS_WIN
#include <QProxyStyle>
class WindowsCorrectedStyle : public QProxyStyle

class IconSelectionCorrectedStyle : public QProxyStyle
{
public:
void drawPrimitive(PrimitiveElement element,
Expand All @@ -171,8 +171,8 @@ class WindowsCorrectedStyle : public QProxyStyle
painter->save();

if (PE_PanelItemViewItem == element) {
// Qt on Windows draws selection backgrounds only for the actual text/icon
// bounding box, not over the full width of a list item.
// Qt on Windows and the Fusion/Phantom base styles draw selection backgrounds only for
// the actual text/icon bounding box, not over the full width of a list item.
// We therefore need to translate and stretch the painter before we can
// tell Qt to draw its native styles.
// Since we are scaling horizontally, we also need to move the right and left
Expand All @@ -186,7 +186,6 @@ class WindowsCorrectedStyle : public QProxyStyle
painter->restore();
}
};
#endif

void CategoryListWidgetDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
Expand All @@ -203,12 +202,7 @@ void CategoryListWidgetDelegate::paint(QPainter* painter,
opt.decorationAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
opt.decorationPosition = QStyleOptionViewItem::Top;

#ifdef Q_OS_WIN
QScopedPointer<QStyle> style(new WindowsCorrectedStyle());
#else
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
#endif

QScopedPointer<QStyle> style(new IconSelectionCorrectedStyle());
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);

QRect fontRect = painter->fontMetrics().boundingRect(
Expand Down
10 changes: 9 additions & 1 deletion src/gui/DatabaseOpenWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<ui version="4.0">
<class>DatabaseOpenWidget</class>
<widget class="QWidget" name="DatabaseOpenWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<height>505</height>
</rect>
</property>
<property name="accessibleName">
<string>Unlock KeePassXC Database</string>
</property>
Expand Down Expand Up @@ -99,7 +107,7 @@
</spacer>
</item>
<item>
<widget class="QFrame" name="horizontalFrame">
<widget class="QFrame" name="loginFrame">
<property name="minimumSize">
<size>
<width>550</width>
Expand Down
15 changes: 9 additions & 6 deletions src/gui/SearchHelpWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>334</width>
<height>249</height>
<width>487</width>
<height>326</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -17,10 +17,7 @@
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
Expand Down Expand Up @@ -58,6 +55,9 @@
<property name="text">
<string>Search terms are as follows: [modifiers][field:][&quot;]term[&quot;]</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
Expand All @@ -77,6 +77,9 @@
<property name="text">
<string>Every search term must match (ie, logical AND)</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
Expand Down
56 changes: 56 additions & 0 deletions src/gui/styles/base/BaseStyle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2020 KeePassXC Team <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QFile>
#include <QStyleFactory>

#include "gui/styles/phantomstyle/phantomstyle.h"
#include "BaseStyle.h"

BaseStyle::BaseStyle()
{
setBaseStyle(new PhantomStyle);
}

BaseStyle::BaseStyle(QProxyStyle* style)
: QProxyStyle(style)
{
}

void BaseStyle::polish(QApplication* app)
{
Q_INIT_RESOURCE(styles);
QString stylesheet;

QFile baseStylesheetFile(":/styles/base/basestyle.qss");
if (baseStylesheetFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
stylesheet = baseStylesheetFile.readAll();
baseStylesheetFile.close();
} else {
qWarning("Failed to load theme base stylesheet.");
}

QFile extensionStyleSheetFile(getStylesheetPath());
if (extensionStyleSheetFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
stylesheet.append(extensionStyleSheetFile.readAll());
extensionStyleSheetFile.close();
} else {
qWarning("Failed to load theme extension stylesheet.");
}

app->setStyleSheet(stylesheet);
}
43 changes: 43 additions & 0 deletions src/gui/styles/base/BaseStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2020 KeePassXC Team <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KEEPASSXC_BASESTYLE_H
#define KEEPASSXC_BASESTYLE_H

#include <QApplication>
#include <QProxyStyle>

class BaseStyle : public QProxyStyle
{
Q_OBJECT

public:
BaseStyle();
explicit BaseStyle(QProxyStyle* style);

using QProxyStyle::polish;
void polish(QApplication* app) override;

protected:
/**
* @return Path to stylesheet which extends basestyle.qss
*/
virtual QString getStylesheetPath() const = 0;
};


#endif //KEEPASSXC_BASESTYLE_H
Loading

0 comments on commit 71e3e0b

Please sign in to comment.