Skip to content

Commit

Permalink
Move serial & firmware version text to extra dialog
Browse files Browse the repository at this point in the history
Clean up the UI more by moving this away, and also allows us to provide
more technical info about the device in the dialog in the future.
  • Loading branch information
z3ntu committed May 4, 2024
1 parent 32a8896 commit b3bbc0e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 22 deletions.
75 changes: 75 additions & 0 deletions src/deviceinfodialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) 2018-2024 Luca Weiss <luca (at) z3ntu (dot) xyz>
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "deviceinfodialog.h"

#include <QFormLayout>
#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>

DeviceInfoDialog::DeviceInfoDialog(libopenrazer::Device *device, QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("RazerGenie - Device info"));
resize(400, 200);
setMinimumSize(QSize(400, 200));

QFont titleFont("Arial", 16, QFont::Bold);

// Layout setup:
// QDialog -> QVBoxLayout mainLayout -> QScrollArea scrollArea -> QWidget contentWidget -> QFormLayout formLayout

QWidget *contentWidget = new QWidget(this);
contentWidget->setMaximumWidth(300);

QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
scrollArea->setFrameShape(QFrame::NoFrame);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setWidget(contentWidget);
scrollArea->setAlignment(Qt::AlignHCenter);

QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(scrollArea);

QFormLayout *formLayout = new QFormLayout(contentWidget);

QLabel *aboutLabel = new QLabel(contentWidget);
aboutLabel->setText(tr("About"));
aboutLabel->setFont(titleFont);
aboutLabel->setAlignment(Qt::AlignHCenter);
formLayout->addRow(aboutLabel);

QFrame *aboutSeparator = new QFrame(this);
aboutSeparator->setFrameShape(QFrame::HLine);
aboutSeparator->setFrameShadow(QFrame::Sunken);
formLayout->addRow(aboutSeparator);

/* Serial number */
QString serial = "error";
try {
serial = device->getSerial();
} catch (const libopenrazer::DBusException &e) {
qWarning("Failed to get serial");
}
QLabel *serialLabel = new QLabel(this);
serialLabel->setText(serial);
serialLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
formLayout->addRow(tr("Serial number:"), serialLabel);

/* Firmware version */
QString firmwareVersion = "error";
try {
firmwareVersion = device->getFirmwareVersion();
} catch (const libopenrazer::DBusException &e) {
qWarning("Failed to get firmware version");
}
QLabel *firmwareVersionLabel = new QLabel(this);
firmwareVersionLabel->setText(firmwareVersion);
firmwareVersionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
formLayout->addRow(tr("Firmware version:"), firmwareVersionLabel);
}

DeviceInfoDialog::~DeviceInfoDialog() = default;
19 changes: 19 additions & 0 deletions src/deviceinfodialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2024 Luca Weiss <luca (at) z3ntu (dot) xyz>
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DEVICEINFODIALOG_H
#define DEVICEINFODIALOG_H

#include <QDialog>
#include <libopenrazer.h>

class DeviceInfoDialog : public QDialog
{
Q_OBJECT
public:
DeviceInfoDialog(libopenrazer::Device *device, QWidget *parent = nullptr);
~DeviceInfoDialog() override;
};

#endif // DEVICEINFODIALOG_H
45 changes: 23 additions & 22 deletions src/devicewidget/devicewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

#include "devicewidget.h"

#include "deviceinfodialog.h"
#include "lightingwidget.h"
#include "performancewidget.h"
#include "powerwidget.h"

#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
#include <QTabWidget>
#include <QVBoxLayout>
Expand All @@ -20,11 +22,30 @@ DeviceWidget::DeviceWidget(libopenrazer::Device *device)

QFont titleFont("Arial", 18, QFont::Bold);

// Add header with the device name
/* Header items */
auto *headerHBox = new QHBoxLayout();

QLabel *header = new QLabel(device->getDeviceName(), this);
header->setFont(titleFont);
verticalLayout->addWidget(header);
headerHBox->addWidget(header);

QPushButton *infoButton = new QPushButton();
infoButton->setText(tr("Device Info"));
infoButton->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed));

QIcon infoIcon = QIcon::fromTheme("help-about-symbolic");
infoButton->setIcon(infoIcon);
connect(infoButton, &QPushButton::pressed, this, [=]() {
auto *info = new DeviceInfoDialog(device, this);
info->setWindowModality(Qt::WindowModal);
info->setAttribute(Qt::WA_DeleteOnClose);
info->show();
});
headerHBox->addWidget(infoButton);

verticalLayout->addLayout(headerHBox);

/* Tabs */
QTabWidget *tabWidget = new QTabWidget(this);

/* Lighting tab */
Expand Down Expand Up @@ -61,26 +82,6 @@ DeviceWidget::DeviceWidget(libopenrazer::Device *device)
}

verticalLayout->addWidget(tabWidget);

/* Serial and firmware version labels */
QString serial = "error";
try {
serial = device->getSerial();
} catch (const libopenrazer::DBusException &e) {
qWarning("Failed to get serial");
}
QString firmwareVersion = "error";
try {
firmwareVersion = device->getFirmwareVersion();
} catch (const libopenrazer::DBusException &e) {
qWarning("Failed to get firmware version");
}

QLabel *serialLabel = new QLabel(tr("Serial number: %1").arg(serial));
verticalLayout->addWidget(serialLabel);

QLabel *fwVerLabel = new QLabel(tr("Firmware version: %1").arg(firmwareVersion));
verticalLayout->addWidget(fwVerLabel);
}

DeviceWidget::~DeviceWidget() = default;
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ razergenie_sources = files([
'devicewidget/performancewidget.cpp',
'devicewidget/powerwidget.cpp',
'preferences/preferences.cpp',
'deviceinfodialog.cpp',
'devicelistwidget.cpp',
'main.cpp',
'razergenie.cpp',
Expand All @@ -37,6 +38,7 @@ processed = qt.preprocess(
'devicewidget/performancewidget.h',
'devicewidget/powerwidget.h',
'preferences/preferences.h',
'deviceinfodialog.h',
'devicelistwidget.h',
'razergenie.h',
'razerimagedownloader.h',
Expand Down

0 comments on commit b3bbc0e

Please sign in to comment.