Skip to content

Commit dbadc37

Browse files
committed
Theme and appearance rework.
- Remove table vertical header. - Consistent accent color across application. - Native system theme on KDE
1 parent 5784e7f commit dbadc37

File tree

9 files changed

+167
-18
lines changed

9 files changed

+167
-18
lines changed

ui/command_buffer_model.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <iostream>
2222
#include <sstream>
23+
#include "color_utils.h"
2324
#include "dive_core/command_hierarchy.h"
2425
#include "dive_tree_view.h"
2526

@@ -92,7 +93,7 @@ QVariant CommandBufferModel::data(const QModelIndex &index, int role) const
9293

9394
uint64_t node_index = index.internalId();
9495
if (role == Qt::ForegroundRole && IsSelected(node_index))
95-
return QColor(255, 128, 128);
96+
return GetTextAccentColor();
9697

9798
if (role != Qt::DisplayRole)
9899
return QVariant();
@@ -457,4 +458,4 @@ bool CommandBufferModel::IsSelected(uint64_t node_index) const
457458
uint32_t bit_element = node_index % 8;
458459
uint8_t mask = 0x1 << bit_element;
459460
return (m_node_is_selected_bit_list[array_index] & mask) != 0;
460-
}
461+
}

ui/command_model.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QStringList>
1919
#include <QTreeWidget>
2020

21+
#include "color_utils.h"
2122
#include "dive_core/command_hierarchy.h"
2223

2324
static_assert(sizeof(void *) == sizeof(uint64_t),
@@ -86,7 +87,7 @@ QVariant CommandModel::data(const QModelIndex &index, int role) const
8687
if (marker_type == Dive::CommandHierarchy::MarkerType::kInsert ||
8788
marker_type == Dive::CommandHierarchy::MarkerType::kBeginEnd)
8889
{
89-
return QVariant(QBrush(QColor(85, 139, 47))); // Shade of green
90+
return QVariant(QBrush(GetTextAccentColor()));
9091
}
9192
}
9293
}

ui/dive_application.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2025 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "dive_application.h"
18+
19+
bool DiveApplication::event(QEvent* e)
20+
{
21+
if (e->type() == QEvent::ApplicationPaletteChange)
22+
{
23+
if (m_style_sheet)
24+
{
25+
// Re-apply style sheet, so palette change is propagated.
26+
setStyleSheet(*m_style_sheet);
27+
}
28+
}
29+
return QApplication::event(e);
30+
}

ui/dive_application.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2025 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <optional>
20+
21+
#include <QApplication>
22+
#include <QEvent>
23+
#include <QString>
24+
25+
class DiveApplication : public QApplication
26+
{
27+
Q_OBJECT
28+
public:
29+
using QApplication::QApplication;
30+
void SetStyleSheet(const QString& style_sheet)
31+
{
32+
m_style_sheet = style_sheet;
33+
setStyleSheet(style_sheet);
34+
}
35+
36+
protected:
37+
virtual bool event(QEvent* e) Q_DECL_OVERRIDE;
38+
39+
private:
40+
std::optional<QString> m_style_sheet;
41+
};

ui/main.cpp

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#include <QDir>
2121
#include <QFile>
2222
#include <QFileInfo>
23+
#include <QProcessEnvironment>
2324
#include <QSplashScreen>
2425
#include <QStyleFactory>
2526
#include <QTimer>
2627
#include <cstdio>
2728
#include <fcntl.h>
2829
#include <iostream>
30+
#include "dive_application.h"
2931
#include "dive_core/common.h"
3032
#include "dive_core/pm4_info.h"
3133
#include "application_controller.h"
@@ -247,29 +249,52 @@ int main(int argc, char *argv[])
247249

248250
// Try setting "Fusion" style. If not found, set "Windows".
249251
// And if that's not found, default to whatever style the factory provides.
250-
if (!SetApplicationStyle("Fusion"))
252+
bool use_default_style = false;
253+
254+
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
255+
QString desktopEnvironment = env.value("XDG_CURRENT_DESKTOP");
256+
if (desktopEnvironment.contains("KDE", Qt::CaseInsensitive))
257+
{
258+
use_default_style = true;
259+
}
260+
261+
if (!use_default_style)
251262
{
252-
if (!SetApplicationStyle("Windows"))
263+
if (!SetApplicationStyle("Fusion"))
253264
{
254-
if (!QStyleFactory::keys().empty())
265+
if (!SetApplicationStyle("Windows"))
255266
{
256-
SetApplicationStyle(QStyleFactory::keys()[0]);
267+
if (!QStyleFactory::keys().empty())
268+
{
269+
SetApplicationStyle(QStyleFactory::keys()[0]);
270+
}
257271
}
258272
}
259273
}
260274

261275
Dive::RegisterCustomMetaType();
262276

263277
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
264-
QApplication app(argc, argv);
278+
DiveApplication app(argc, argv);
265279
app.setWindowIcon(QIcon(":/images/dive.ico"));
266-
SetDarkMode(app);
267280

268-
// Load and apply the style sheet
269-
QFile style_sheet(":/stylesheet.qss");
270-
style_sheet.open(QFile::ReadOnly);
271-
QString style(style_sheet.readAll());
272-
app.setStyleSheet(style);
281+
if (!use_default_style)
282+
{
283+
SetDarkMode(app);
284+
// Load and apply the style sheet
285+
QFile style_sheet(":/stylesheet.qss");
286+
style_sheet.open(QFile::ReadOnly);
287+
QString style(style_sheet.readAll());
288+
app.SetStyleSheet(style);
289+
}
290+
else
291+
{
292+
// Load and apply the style sheet
293+
QFile style_sheet(":/stylesheet_adaptive.qss");
294+
style_sheet.open(QFile::ReadOnly);
295+
QString style(style_sheet.readAll());
296+
app.SetStyleSheet(style);
297+
}
273298

274299
// Display splash screen
275300
QSplashScreen *splash_screen = new QSplashScreen();
@@ -285,6 +310,7 @@ int main(int argc, char *argv[])
285310
{
286311
QObject::connect(main_window, &MainWindow::FileLoaded, main_window, &MainWindow::close);
287312
}
313+
main_window->SetUseDefaultStyle(use_default_style);
288314

289315
if (!controller.InitializePlugins())
290316
{

ui/main_window.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ void MainWindow::CreateActions()
16371637
{
16381638
// Open file action
16391639
m_open_action = new QAction(tr("&Open"), this);
1640-
m_open_action->setIcon(QIcon(":/images/open.png"));
1640+
m_open_action->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOpenButton));
16411641
m_open_action->setShortcuts(QKeySequence::Open);
16421642
m_open_action->setStatusTip(tr("Open an existing capture"));
16431643
connect(m_open_action, &QAction::triggered, this, &MainWindow::OnOpenFile);
@@ -1652,7 +1652,7 @@ void MainWindow::CreateActions()
16521652
// Save file action
16531653
m_save_action = new QAction(tr("&Save"), this);
16541654
m_save_action->setStatusTip(tr("Save the current capture"));
1655-
m_save_action->setIcon(QIcon(":/images/save.png"));
1655+
m_save_action->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton));
16561656
m_save_action->setShortcut(QKeySequence::Save);
16571657
m_save_action->setEnabled(false);
16581658
connect(m_save_action, &QAction::triggered, this, &MainWindow::OnSaveCapture);
@@ -1670,6 +1670,7 @@ void MainWindow::CreateActions()
16701670
for (auto &action : m_recent_file_actions)
16711671
{
16721672
action = new QAction(this);
1673+
action->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
16731674
action->setVisible(false);
16741675
connect(action, SIGNAL(triggered()), this, SLOT(OpenRecentFile()));
16751676
}
@@ -1819,7 +1820,10 @@ void MainWindow::CreateStatusBar()
18191820
{
18201821
// Create status bar on the main window.
18211822
m_status_bar = new QStatusBar(this);
1822-
m_status_bar->setStyleSheet("background:#D0D0D0; color:#282828");
1823+
if (!m_use_default_style)
1824+
{
1825+
m_status_bar->setStyleSheet("background:#D0D0D0; color:#282828");
1826+
}
18231827
setStatusBar(m_status_bar);
18241828
}
18251829

ui/main_window.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class MainWindow : public QMainWindow
125125
~MainWindow();
126126
bool LoadFile(const std::string &file_name, bool is_temp_file = false, bool async = true);
127127

128+
void SetUseDefaultStyle(bool use_default_style) { m_use_default_style = use_default_style; }
129+
128130
protected:
129131
virtual void closeEvent(QCloseEvent *closeEvent) Q_DECL_OVERRIDE;
130132

@@ -238,6 +240,8 @@ private slots:
238240
CorrelationTarget target);
239241

240242
ApplicationController &m_controller;
243+
244+
bool m_use_default_style = false;
241245

242246
QMenu *m_file_menu;
243247
QMenu *m_recent_captures_menu;

ui/resources.qrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
<file>images/dive.png</file>
1818
<file>images/dive.ico</file>
1919
<file>stylesheet.qss</file>
20+
<file>stylesheet_adaptive.qss</file>
2021
<file>images/filter.png</file>
2122
<file>images/analyze.png</file>
2223
<file>images/copy.png</file>
2324
</qresource>
24-
</RCC>
25+
</RCC>

ui/stylesheet_adaptive.qss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* QTreeView style */
2+
3+
QTreeView {
4+
show-decoration-selected: 1;
5+
}
6+
7+
QTreeView::branch:has-siblings:!adjoins-item {
8+
border-image: url(\":/images/vline.png\") 0;
9+
}
10+
11+
QTreeView::branch:has-siblings:adjoins-item {
12+
border-image: url(\":/images/branch_more.png\") 0;
13+
}
14+
15+
QTreeView::branch:!has-children:!has-siblings:adjoins-item {
16+
border-image: url(\":/images/branch_end.png\") 0;
17+
}
18+
19+
QTreeView::branch:has-children:!has-siblings:closed,
20+
QTreeView::branch:closed:has-children:has-siblings {
21+
border-image: none;
22+
image: url(\":/images/branch_closed.png\");
23+
}
24+
25+
QTreeView::branch:open:has-children:!has-siblings,
26+
QTreeView::branch:open:has-children:has-siblings {
27+
border-image: none;
28+
image: url(\":/images/branch_open.png\");
29+
}
30+
31+
/* Style for the hover help label */
32+
QLabel#hoverHelpLabel {
33+
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
34+
border-radius: 5px;
35+
color: #000;
36+
padding: 3px;
37+
}
38+
39+
QLabel#propertyPanelLabel {
40+
font - family : Arial, Helvetica, sans - serif;
41+
}

0 commit comments

Comments
 (0)