Skip to content

Commit

Permalink
Integrate ProgressWidget with status bar in MainWindow.
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Sep 19, 2024
1 parent 185b916 commit 1508115
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 173 deletions.
11 changes: 7 additions & 4 deletions Guitar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ SOURCES += \
src/texteditor/unicode.cpp \
src/urlencode.cpp \
src/webclient.cpp \
src/AboutDialog.cpp \
src/coloredit/RingSlider.cpp
src/AboutDialog.cpp \
src/coloredit/RingSlider.cpp \
src/ProgressWidget.cpp

HEADERS += \
$$PWD/src/FileListWidget.h \
Expand Down Expand Up @@ -424,7 +425,8 @@ HEADERS += \
src/texteditor/UnicodeWidth.h \
src/texteditor/unicode.h \
src/urlencode.h \
src/webclient.h
src/webclient.h \
src/ProgressWidget.h

HEADERS += version.h

Expand Down Expand Up @@ -496,7 +498,8 @@ FORMS += \
src/WelcomeWizardDialog.ui \
src/coloredit/ColorDialog.ui \
src/coloredit/ColorEditWidget.ui \
src/ManageWorkingFolderDialog.ui
src/ManageWorkingFolderDialog.ui \
src/ProgressWidget.ui

RESOURCES += \
src/resources/resources.qrc
Expand Down
39 changes: 20 additions & 19 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "common/misc.h"
#include "GitConfigGlobalAddSafeDirectoryDialog.h"
#include "GitProcessThread.h"
#include "ProgressWidget.h"
#include "gunzip.h"
#include "platform.h"
#include "webclient.h"
Expand Down Expand Up @@ -161,7 +162,7 @@ struct MainWindow::Private {
QTimer interval_10ms_timer;
QImage graph_color;
QPixmap digits;
StatusLabel *status_bar_label;
ProgressWidget *status_bar_label;

QObject *last_focused_file_list = nullptr;

Expand Down Expand Up @@ -204,7 +205,6 @@ MainWindow::MainWindow(QWidget *parent)
, m(new Private)
{
ui->setupUi(this);
ui->frame_progress->setVisible(false);

setupShowFileListHandler();
setupProgressHandler();
Expand Down Expand Up @@ -251,7 +251,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->splitter_v->setSizes({100, 400});
ui->splitter_h->setSizes({200, 100, 200});

m->status_bar_label = new StatusLabel(this);
m->status_bar_label = new ProgressWidget(this);
ui->statusBar->addWidget(m->status_bar_label);

frame()->filediffwidget()->init();
Expand Down Expand Up @@ -739,16 +739,6 @@ void MainWindow::toggleMaximized()
setWindowState(state);
}

void MainWindow::setStatusBarText(QString const &text)
{
m->status_bar_label->setText(text);
}

void MainWindow::clearStatusBarText()
{
setStatusBarText(QString());
}

void MainWindow::onLogVisibilityChanged()
{
ui->action_window_log->setChecked(ui->dockWidget_log->isVisible());
Expand Down Expand Up @@ -838,10 +828,21 @@ void MainWindow::setupProgressHandler()
connect(this, &MainWindow::signalShowProgress, this, &MainWindow::onShowProgress);
}

void MainWindow::setStatusBarText(QString const &text)
{
m->status_bar_label->setVisible(false);
ui->statusBar->showMessage(text);
}

void MainWindow::clearStatusBarText()
{
setStatusBarText(QString());
}

void MainWindow::onSetProgress(float progress)
{
ASSERT_MAIN_THREAD();
ui->label_progress->setProgress(progress);
m->status_bar_label->setProgress(progress);
}

void MainWindow::setProgress(float progress)
Expand All @@ -852,10 +853,10 @@ void MainWindow::setProgress(float progress)
void MainWindow::onShowProgress(const QString &text, bool cancel_button)
{
ASSERT_MAIN_THREAD();
ui->toolButton_cancel->setVisible(cancel_button);
ui->label_progress->setText(text);
ui->label_progress->setProgress(-1.0f);
ui->frame_progress->setVisible(!text.isEmpty());

ui->statusBar->clearMessage();
m->status_bar_label->setVisible(true);
m->status_bar_label->setText(text);
}

void MainWindow::showProgress(QString const &text, bool cancel_button)
Expand All @@ -866,7 +867,7 @@ void MainWindow::showProgress(QString const &text, bool cancel_button)
void MainWindow::onHideProgress()
{
ASSERT_MAIN_THREAD();
ui->frame_progress->setVisible(false);
m->status_bar_label->clear();
}

void MainWindow::hideProgress()
Expand Down
117 changes: 0 additions & 117 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -365,118 +365,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="frame_progress">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="MyToolButton" name="toolButton_cancel">
<property name="minimumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset resource="resources/resources.qrc">
<normaloff>:/image/redsquare.svg</normaloff>:/image/redsquare.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonStyle::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="ProgressTextLabel" name="label_progress">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="RepositoryInfoFrame" name="frame_3">
<property name="sizePolicy">
Expand Down Expand Up @@ -1935,11 +1823,6 @@
<extends>QTreeWidget</extends>
<header>RepositoriesTreeWidget.h</header>
</customwidget>
<customwidget>
<class>ProgressTextLabel</class>
<extends>QLabel</extends>
<header>ProgressTextLabel.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tableWidget_log</tabstop>
Expand Down
76 changes: 43 additions & 33 deletions src/ProgressTextLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,57 @@ ProgressTextLabel::ProgressTextLabel(QWidget *parent)

}

void ProgressTextLabel::setElementVisible(bool bar, bool msg)
{
bar_visible = bar;
msg_visible = msg;
}

void ProgressTextLabel::setProgress(float progress)
{
progress_ = progress;
}

void ProgressTextLabel::paintEvent(QPaintEvent *event)
{
QPainter pr(this);
QRect rect(0, height() - 10, width(), 6);
pr.fillRect(rect, Qt::black);
rect.adjust(1, 1, -1, -1);
pr.setClipRect(rect);
if (progress_ > 0) {
float progress = std::min(progress_, 1.0f);
rect.setRight(rect.left() + rect.width() * progress);
pr.fillRect(rect, Qt::green);
} else if (progress_ < 0) {
QBrush br0(Qt::cyan);
QBrush br1(Qt::black);
int x = animation_ - 16;
bool color = false;
while (x < width()) {
QPainterPath path;
int px = x;
int py = rect.bottom();
path.moveTo(px, py);
px += 8;
py -= 8;
path.lineTo(px, py);
px += 8;
path.lineTo(px, py);
px -= 8;
py += 8;
path.lineTo(px, py);
px -= 8;
path.lineTo(px, py);
pr.fillPath(path, color ? br1 : br0);
color = !color;
x += 8;
if (bar_visible) {
QPainter pr(this);
QRect rect(0, height() - 10, width(), 6);
pr.fillRect(rect, Qt::black);
rect.adjust(1, 1, -1, -1);
pr.setClipRect(rect);
if (progress_ > 0) {
float progress = std::min(progress_, 1.0f);
rect.setRight(rect.left() + rect.width() * progress);
pr.fillRect(rect, Qt::green);
} else if (progress_ < 0) {
QBrush br0(Qt::cyan);
QBrush br1(Qt::black);
int x = animation_ - 16;
bool color = false;
while (x < width()) {
QPainterPath path;
int px = x;
int py = rect.bottom();
path.moveTo(px, py);
px += 8;
py -= 8;
path.lineTo(px, py);
px += 8;
path.lineTo(px, py);
px -= 8;
py += 8;
path.lineTo(px, py);
px -= 8;
path.lineTo(px, py);
pr.fillPath(path, color ? br1 : br0);
color = !color;
x += 8;
}
}
}

QLabel::paintEvent(event);
if (msg_visible) {
QLabel::paintEvent(event);
}
}
3 changes: 3 additions & 0 deletions src/ProgressTextLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class ProgressTextLabel : public QLabel {
float progress_ = 0;
QTimer timer_;
int animation_ = 0;
bool bar_visible = true;
bool msg_visible = true;
protected:
void paintEvent(QPaintEvent *event);
public:
ProgressTextLabel(QWidget *parent = nullptr);
void setElementVisible(bool bar, bool msg);
void setProgress(float progress);
};

Expand Down
31 changes: 31 additions & 0 deletions src/ProgressWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "ProgressWidget.h"
#include "ui_ProgressWidget.h"

ProgressWidget::ProgressWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::ProgressWidget)
{
ui->setupUi(this);
}

ProgressWidget::~ProgressWidget()
{
delete ui;
}

void ProgressWidget::setProgress(float progress)
{
ui->label_bar->setProgress(progress);
}

void ProgressWidget::setText(const QString &text)
{
ui->label_text->setText(text);
}

void ProgressWidget::clear()
{
setText({});
setProgress(0.0f);
setVisible(false);
}
Loading

0 comments on commit 1508115

Please sign in to comment.