Skip to content

Commit

Permalink
MainWindow: use TTabWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
gperciva committed Apr 25, 2022
1 parent 6af5c3e commit ba7f8f9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 44 deletions.
2 changes: 2 additions & 0 deletions Tarsnap.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOURCES += \
lib/widgets/TPathComboBrowse.cpp \
lib/widgets/TPathLineBrowse.cpp \
lib/widgets/TPopupPushButton.cpp \
lib/widgets/TTabWidget.cpp \
lib/widgets/TTextView.cpp \
lib/widgets/TWizard.cpp \
lib/widgets/TWizardPage.cpp \
Expand Down Expand Up @@ -116,6 +117,7 @@ HEADERS += \
lib/widgets/TPathComboBrowse.h \
lib/widgets/TPathLineBrowse.h \
lib/widgets/TPopupPushButton.h \
lib/widgets/TTabWidget.h \
lib/widgets/TTextView.h \
lib/widgets/TWizard.h \
lib/widgets/TWizardPage.h \
Expand Down
14 changes: 13 additions & 1 deletion forms/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTabWidget" name="mainTabWidget">
<widget class="TTabWidget" name="mainTabWidget">
<property name="minimumSize">
<size>
<width>0</width>
Expand Down Expand Up @@ -103,6 +103,12 @@ border-radius: 2px;
<property name="currentIndex">
<number>0</number>
</property>
<property name="largeLogoFilename">
<string notr="true">:/logos/tarsnap-header-h29.png</string>
</property>
<property name="smallLogoFilename">
<string notr="true">:/logos/tarsnap-icon-h29.png</string>
</property>
<widget class="BackupTabWidget" name="backupTabWidget">
<property name="acceptDrops">
<bool>false</bool>
Expand Down Expand Up @@ -692,6 +698,12 @@ font-size: 12px;
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>TTabWidget</class>
<extends>QTabWidget</extends>
<header>TTabWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TTextView</class>
<extends>QPlainTextEdit</extends>
Expand Down
40 changes: 0 additions & 40 deletions src/widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ WARNINGS_ENABLE
#include "widgets/settingswidget.h"
#include "widgets/stoptasksdialog.h"

#define MAIN_LOGO_RIGHT_MARGIN 5
#define MAIN_LOGO_FUDGE (-10)

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
_ui(new Ui::MainWindow),
_minWidth(0),
_menuBar(nullptr),
_aboutToQuit(false),
_backupTaskRunning(false),
Expand Down Expand Up @@ -273,42 +269,6 @@ void MainWindow::backupTabValidStatus(bool valid)
_ui->actionBackupMorphIntoJob->setEnabled(valid);
}

void MainWindow::paintEvent(QPaintEvent *event)
{
(void)event; /* UNUSED */
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
if(_minWidth == 0)
_minWidth = _ui->mainTabWidget->tabBar()->width();
// Find out how much room is left to display an icon, including a
// "fudge factor" to accommodate margins.
int remaining_width = frameGeometry().width() - _minWidth + MAIN_LOGO_FUDGE;

// Compare with the width of the png files.
QPixmap logoPixmap(":/logos/tarsnap-header-h29.png");
QPixmap iconPixmap(":/logos/tarsnap-icon-h29.png");

// Pick which image (if any) to use
QPixmap *pixmap;
if(remaining_width > logoPixmap.width())
pixmap = &logoPixmap;
else if(remaining_width > iconPixmap.width())
pixmap = &iconPixmap;
else
pixmap = nullptr;

// Draw image
if(pixmap != nullptr)
{
QIcon icon(*pixmap);
int x = width() - MAIN_LOGO_RIGHT_MARGIN - pixmap->width();
int y = _ui->mainContentSplitter->y() + _ui->centralWidget->y();
icon.paint(&p, x, y, pixmap->width(), pixmap->height());
}
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
switch(event->key())
Expand Down
3 changes: 0 additions & 3 deletions src/widgets/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ public slots:
void cancelTaskRequested(BaseTask *task, const QUuid uuid);

protected:
//! Draw the Tarsnap logo in the top-right corner.
void paintEvent(QPaintEvent *event) override;
//! Handles the escape key; passes other events on.
void keyPressEvent(QKeyEvent *event) override;
//! Start checking whether there are running tasks.
Expand All @@ -187,7 +185,6 @@ private slots:

private:
Ui::MainWindow *_ui;
int _minWidth;
QMenuBar *_menuBar;
bool _aboutToQuit;
bool _backupTaskRunning;
Expand Down
2 changes: 2 additions & 0 deletions tests/mainwindow/test-mainwindow.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ HEADERS += \
../../lib/widgets/TBusyLabel.h \
../../lib/widgets/TElidedLabel.h \
../../lib/widgets/TPopupPushButton.h \
../../lib/widgets/TTabWidget.h \
../../lib/widgets/TTextView.h \
../../src/backuptask.h \
../../src/basetask.h \
Expand Down Expand Up @@ -97,6 +98,7 @@ SOURCES += test-mainwindow.cpp \
../../lib/widgets/TBusyLabel.cpp \
../../lib/widgets/TElidedLabel.cpp \
../../lib/widgets/TPopupPushButton.cpp \
../../lib/widgets/TTabWidget.cpp \
../../lib/widgets/TTextView.cpp \
../../src/backuptask.cpp \
../../src/basetask.cpp \
Expand Down

0 comments on commit ba7f8f9

Please sign in to comment.