Skip to content

Commit

Permalink
Replace KSeparator with custom class
Browse files Browse the repository at this point in the history
  • Loading branch information
equeim committed Dec 9, 2023
1 parent 032afca commit 6f90518
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
34 changes: 28 additions & 6 deletions src/ui/screens/mainwindow/mainwindowstatusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <QIcon>
#include <QLabel>
#include <QMenu>

#include <KSeparator>
#include <QPainter>
#include <QStyleOption>

#include "log/log.h"
#include "rpc/serverstats.h"
Expand All @@ -30,23 +30,25 @@ namespace tremotesf {
addPermanentWidget(container, 1);

auto layout = new QHBoxLayout(container);
layout->setContentsMargins(8, 4, 8, 4);
// Top/bottom margins are set on mServerLabel below so that they don't affect separators
layout->setContentsMargins(8, 0, 8, 0);

mNoServersErrorImage = new QLabel(this);
mNoServersErrorImage->setPixmap(QIcon::fromTheme("dialog-error"_l1).pixmap(16, 16));
mNoServersErrorImage->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
layout->addWidget(mNoServersErrorImage);

mServerLabel = new QLabel(this);
mServerLabel->setContentsMargins(0, 5, 0, 5);
layout->addWidget(mServerLabel);

mFirstSeparator = new KSeparator(Qt::Vertical, this);
mFirstSeparator = new StatusBarSeparator(this);
layout->addWidget(mFirstSeparator);

mStatusLabel = new QLabel(this);
layout->addWidget(mStatusLabel);

mSecondSeparator = new KSeparator(Qt::Vertical, this);
mSecondSeparator = new StatusBarSeparator(this);
layout->addWidget(mSecondSeparator);

mDownloadSpeedImage = new QLabel(this);
Expand All @@ -57,7 +59,7 @@ namespace tremotesf {
mDownloadSpeedLabel = new QLabel(this);
layout->addWidget(mDownloadSpeedLabel);

mThirdSeparator = new KSeparator(Qt::Vertical, this);
mThirdSeparator = new StatusBarSeparator(this);
layout->addWidget(mThirdSeparator);

mUploadSpeedImage = new QLabel(this);
Expand Down Expand Up @@ -188,4 +190,24 @@ namespace tremotesf {
});
menu->popup(QCursor::pos());
}

StatusBarSeparator::StatusBarSeparator(QWidget* parent) : QWidget(parent) {
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
}

QSize StatusBarSeparator::sizeHint() const {
QStyleOption opt{};
opt.initFrom(this);
opt.state.setFlag(QStyle::State_Horizontal);
const int extent = style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, &opt, this);
return {extent, extent};
}

void StatusBarSeparator::paintEvent(QPaintEvent*) {
QPainter p(this);
QStyleOption opt{};
opt.initFrom(this);
opt.state.setFlag(QStyle::State_Horizontal);
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, &p, this);
}
}
19 changes: 15 additions & 4 deletions src/ui/screens/mainwindow/mainwindowstatusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#include <QStatusBar>

class QLabel;
class KSeparator;

namespace tremotesf {
class Rpc;

class StatusBarSeparator;

class MainWindowStatusBar final : public QStatusBar {
Q_OBJECT

Expand All @@ -28,18 +29,28 @@ namespace tremotesf {
const Rpc* mRpc{};
QLabel* mNoServersErrorImage{};
QLabel* mServerLabel{};
KSeparator* mFirstSeparator{};
StatusBarSeparator* mFirstSeparator{};
QLabel* mStatusLabel{};
KSeparator* mSecondSeparator{};
StatusBarSeparator* mSecondSeparator{};
QLabel* mDownloadSpeedImage{};
QLabel* mDownloadSpeedLabel{};
KSeparator* mThirdSeparator{};
StatusBarSeparator* mThirdSeparator{};
QLabel* mUploadSpeedImage{};
QLabel* mUploadSpeedLabel{};

signals:
void showConnectionSettingsDialog();
};

class StatusBarSeparator final : public QWidget {
Q_OBJECT
public:
explicit StatusBarSeparator(QWidget* parent = nullptr);
QSize sizeHint() const override;

protected:
void paintEvent(QPaintEvent* event) override;
};
}

#endif // TREMOTESF_MAINWINDOWSTATUSBAR_H

0 comments on commit 6f90518

Please sign in to comment.