1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #4122

Jimi Huotari (1):
      feat(UI): Move filetransferwidget buttons side-by-side.
This commit is contained in:
sudden6 2017-03-02 10:42:54 +01:00
commit b14a35aa76
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
3 changed files with 199 additions and 176 deletions

View File

@ -40,6 +40,11 @@
#include <math.h> #include <math.h>
// The leftButton is used to accept, pause, or resume a file transfer, as well as to open a
// received file.
// The rightButton is used to cancel a file transfer, or to open the directory a file was
// downloaded to.
FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file) FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::FileTransferWidget) , ui(new Ui::FileTransferWidget)
@ -47,6 +52,7 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file)
, lastTick(QTime::currentTime()) , lastTick(QTime::currentTime())
, backgroundColor(Style::getColor(Style::LightGrey)) , backgroundColor(Style::getColor(Style::LightGrey))
, buttonColor(Style::getColor(Style::Yellow)) , buttonColor(Style::getColor(Style::Yellow))
, buttonBackgroundColor(Style::getColor(Style::White))
, active(true) , active(true)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -93,8 +99,10 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file)
&FileTransferWidget::fileTransferRemotePausedUnpaused); &FileTransferWidget::fileTransferRemotePausedUnpaused);
connect(Core::getInstance(), &Core::fileTransferBrokenUnbroken, this, connect(Core::getInstance(), &Core::fileTransferBrokenUnbroken, this,
&FileTransferWidget::fileTransferBrokenUnbroken); &FileTransferWidget::fileTransferBrokenUnbroken);
connect(ui->topButton, &QPushButton::clicked, this, &FileTransferWidget::onTopButtonClicked); connect(ui->leftButton, &QPushButton::clicked, this,
connect(ui->bottomButton, &QPushButton::clicked, this, &FileTransferWidget::onBottomButtonClicked); &FileTransferWidget::onLeftButtonClicked);
connect(ui->rightButton, &QPushButton::clicked, this,
&FileTransferWidget::onRightButtonClicked);
connect(ui->previewButton, &QPushButton::clicked, this, connect(ui->previewButton, &QPushButton::clicked, this,
&FileTransferWidget::onPreviewButtonClicked); &FileTransferWidget::onPreviewButtonClicked);
@ -190,8 +198,8 @@ void FileTransferWidget::setButtonColor(const QColor& c)
bool FileTransferWidget::drawButtonAreaNeeded() const bool FileTransferWidget::drawButtonAreaNeeded() const
{ {
return (ui->bottomButton->isVisible() || ui->topButton->isVisible()) return (ui->rightButton->isVisible() || ui->leftButton->isVisible())
&& !(ui->topButton->isVisible() && ui->topButton->objectName() == "ok"); && !(ui->leftButton->isVisible() && ui->leftButton->objectName() == "ok");
} }
void FileTransferWidget::paintEvent(QPaintEvent*) void FileTransferWidget::paintEvent(QPaintEvent*)
@ -203,27 +211,45 @@ void FileTransferWidget::paintEvent(QPaintEvent*)
qreal ratio = static_cast<qreal>(geometry().height()) / static_cast<qreal>(geometry().width()); qreal ratio = static_cast<qreal>(geometry().height()) / static_cast<qreal>(geometry().width());
const int r = 24; const int r = 24;
const int buttonFieldWidth = 34; const int buttonFieldWidth = 32;
const int lineWidth = 1; const int lineWidth = 1;
// draw background // draw background
if (drawButtonAreaNeeded()) if (drawButtonAreaNeeded())
painter.setClipRect(QRect(0, 0, width() - buttonFieldWidth, height())); // Draw the widget background:
painter.setClipRect(QRect(0, 0, width(), height()));
painter.setBrush(QBrush(backgroundColor)); painter.setBrush(QBrush(backgroundColor));
painter.drawRoundRect(geometry(), r * ratio, r); painter.drawRoundRect(geometry(), r * ratio, r);
if (drawButtonAreaNeeded()) { if (drawButtonAreaNeeded()) {
// draw button background (top) // Draw the button background:
painter.setBrush(QBrush(buttonColor)); QPainterPath buttonBackground;
painter.setClipRect(QRect(width() - buttonFieldWidth + lineWidth, 0, buttonFieldWidth, buttonBackground.addRoundRect(width()-2*buttonFieldWidth-lineWidth*2, 0, buttonFieldWidth,
height() / 2 - ceil(lineWidth / 2.0))); buttonFieldWidth+lineWidth, 50, 50);
painter.drawRoundRect(geometry(), r * ratio, r); buttonBackground.addRect(width()-2*buttonFieldWidth-lineWidth*2, 0, buttonFieldWidth*2,
buttonFieldWidth/2);
buttonBackground.addRect(width()-1.5*buttonFieldWidth-lineWidth*2, 0, buttonFieldWidth*2,
buttonFieldWidth+1);
buttonBackground.setFillRule(Qt::WindingFill);
painter.setBrush(QBrush(buttonBackgroundColor));
painter.drawPath(buttonBackground);
// draw button background (bottom) // Draw the left button:
QPainterPath leftButton;
leftButton.addRoundRect(QRect(width()-2*buttonFieldWidth-lineWidth, 0, buttonFieldWidth,
buttonFieldWidth), 50, 50);
leftButton.addRect(QRect(width()-2*buttonFieldWidth-lineWidth, 0, buttonFieldWidth/2,
buttonFieldWidth/2));
leftButton.addRect(QRect(width()-1.5*buttonFieldWidth-lineWidth, 0, buttonFieldWidth/2,
buttonFieldWidth));
leftButton.setFillRule(Qt::WindingFill);
painter.setBrush(QBrush(buttonColor)); painter.setBrush(QBrush(buttonColor));
painter.setClipRect(QRect(width() - buttonFieldWidth + lineWidth, painter.drawPath(leftButton);
height() / 2 + lineWidth / 2, buttonFieldWidth, height() / 2));
// Draw the right button:
painter.setBrush(QBrush(buttonColor));
painter.setClipRect(QRect(width()-buttonFieldWidth, 0, buttonFieldWidth,
buttonFieldWidth));
painter.drawRoundRect(geometry(), r * ratio, r); painter.drawRoundRect(geometry(), r * ratio, r);
} }
} }
@ -363,15 +389,15 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
setupButtons(); setupButtons();
hideWidgets(); hideWidgets();
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg")); ui->leftButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg"));
ui->topButton->setObjectName("ok"); ui->leftButton->setObjectName("ok");
ui->topButton->setToolTip(tr("Open file")); ui->leftButton->setToolTip(tr("Open file"));
ui->topButton->show(); ui->leftButton->show();
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/dir.svg")); ui->rightButton->setIcon(QIcon(":/ui/fileTransferInstance/dir.svg"));
ui->bottomButton->setObjectName("dir"); ui->rightButton->setObjectName("dir");
ui->bottomButton->setToolTip(tr("Open file directory")); ui->rightButton->setToolTip(tr("Open file directory"));
ui->bottomButton->show(); ui->rightButton->show();
// preview // preview
if (fileInfo.direction == ToxFile::RECEIVING) if (fileInfo.direction == ToxFile::RECEIVING)
@ -408,8 +434,8 @@ QString FileTransferWidget::getHumanReadableSize(qint64 size)
void FileTransferWidget::hideWidgets() void FileTransferWidget::hideWidgets()
{ {
ui->topButton->hide(); ui->leftButton->hide();
ui->bottomButton->hide(); ui->rightButton->hide();
ui->progressBar->hide(); ui->progressBar->hide();
ui->progressLabel->hide(); ui->progressLabel->hide();
ui->etaLabel->hide(); ui->etaLabel->hide();
@ -419,43 +445,43 @@ void FileTransferWidget::setupButtons()
{ {
switch (fileInfo.status) { switch (fileInfo.status) {
case ToxFile::TRANSMITTING: case ToxFile::TRANSMITTING:
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg")); ui->leftButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg"));
ui->topButton->setObjectName("pause"); ui->leftButton->setObjectName("pause");
ui->topButton->setToolTip(tr("Pause transfer")); ui->leftButton->setToolTip(tr("Pause transfer"));
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg")); ui->rightButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg"));
ui->bottomButton->setObjectName("cancel"); ui->rightButton->setObjectName("cancel");
ui->bottomButton->setToolTip(tr("Cancel transfer")); ui->rightButton->setToolTip(tr("Cancel transfer"));
setButtonColor(Style::getColor(Style::Green)); setButtonColor(Style::getColor(Style::Green));
break; break;
case ToxFile::PAUSED: case ToxFile::PAUSED:
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/arrow_white.svg")); ui->leftButton->setIcon(QIcon(":/ui/fileTransferInstance/arrow_white.svg"));
ui->topButton->setObjectName("resume"); ui->leftButton->setObjectName("resume");
ui->topButton->setToolTip(tr("Resume transfer")); ui->leftButton->setToolTip(tr("Resume transfer"));
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg")); ui->rightButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg"));
ui->bottomButton->setObjectName("cancel"); ui->rightButton->setObjectName("cancel");
ui->bottomButton->setToolTip(tr("Cancel transfer")); ui->rightButton->setToolTip(tr("Cancel transfer"));
setButtonColor(Style::getColor(Style::LightGrey)); setButtonColor(Style::getColor(Style::LightGrey));
break; break;
case ToxFile::STOPPED: case ToxFile::STOPPED:
case ToxFile::BROKEN: case ToxFile::BROKEN:
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg")); ui->rightButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg"));
ui->bottomButton->setObjectName("cancel"); ui->rightButton->setObjectName("cancel");
ui->bottomButton->setToolTip(tr("Cancel transfer")); ui->rightButton->setToolTip(tr("Cancel transfer"));
if (fileInfo.direction == ToxFile::SENDING) { if (fileInfo.direction == ToxFile::SENDING) {
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg")); ui->leftButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg"));
ui->topButton->setObjectName("pause"); ui->leftButton->setObjectName("pause");
ui->topButton->setToolTip(tr("Pause transfer")); ui->leftButton->setToolTip(tr("Pause transfer"));
} else { } else {
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg")); ui->leftButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg"));
ui->topButton->setObjectName("accept"); ui->leftButton->setObjectName("accept");
ui->topButton->setToolTip(tr("Accept transfer")); ui->leftButton->setToolTip(tr("Accept transfer"));
} }
break; break;
} }
@ -526,14 +552,14 @@ void FileTransferWidget::showPreview(const QString& filename)
} }
} }
void FileTransferWidget::onTopButtonClicked() void FileTransferWidget::onLeftButtonClicked()
{ {
handleButton(ui->topButton); handleButton(ui->leftButton);
} }
void FileTransferWidget::onBottomButtonClicked() void FileTransferWidget::onRightButtonClicked()
{ {
handleButton(ui->bottomButton); handleButton(ui->rightButton);
} }
void FileTransferWidget::onPreviewButtonClicked() void FileTransferWidget::onPreviewButtonClicked()

View File

@ -69,8 +69,8 @@ protected:
virtual void paintEvent(QPaintEvent*) final override; virtual void paintEvent(QPaintEvent*) final override;
private slots: private slots:
void onTopButtonClicked(); void onLeftButtonClicked();
void onBottomButtonClicked(); void onRightButtonClicked();
void onPreviewButtonClicked(); void onPreviewButtonClicked();
private: private:
@ -85,6 +85,7 @@ private:
QVariantAnimation* buttonColorAnimation = nullptr; QVariantAnimation* buttonColorAnimation = nullptr;
QColor backgroundColor; QColor backgroundColor;
QColor buttonColor; QColor buttonColor;
QColor buttonBackgroundColor;
static const uint8_t TRANSFER_ROLLING_AVG_COUNT = 4; static const uint8_t TRANSFER_ROLLING_AVG_COUNT = 4;
uint8_t meanIndex = 0; uint8_t meanIndex = 0;

View File

@ -118,6 +118,86 @@
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="CroppingLabel" name="filenameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Filename</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>12</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="value">
<number>24</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="format">
<string/>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QWidget" name="statusWidget" native="true"> <widget class="QWidget" name="statusWidget" native="true">
<layout class="QHBoxLayout" name="_2"> <layout class="QHBoxLayout" name="_2">
@ -187,86 +267,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>12</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="value">
<number>24</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="format">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="CroppingLabel" name="filenameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Filename</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
@ -325,8 +325,20 @@
</item> </item>
</layout> </layout>
</item> </item>
<item> <item alignment="Qt::AlignTop">
<widget class="QWidget" name="buttonWidget" native="true"> <widget class="QWidget" name="buttonWidget" native="true">
<property name="minimumSize">
<size>
<width>65</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>65</width>
<height>32</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
@ -343,18 +355,24 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<item row="1" column="0"> <item row="0" column="3" alignment="Qt::AlignRight">
<widget class="QPushButton" name="bottomButton"> <widget class="QPushButton" name="rightButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>32</width> <width>32</width>
<height>16777215</height> <height>32</height>
</size> </size>
</property> </property>
<property name="cursor"> <property name="cursor">
@ -369,24 +387,30 @@
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
<width>32</width> <width>14</width>
<height>18</height> <height>14</height>
</size> </size>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="2" alignment="Qt::AlignLeft">
<widget class="QPushButton" name="topButton"> <widget class="QPushButton" name="leftButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>32</width> <width>32</width>
<height>16777215</height> <height>32</height>
</size> </size>
</property> </property>
<property name="cursor"> <property name="cursor">
@ -401,38 +425,12 @@
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
<width>32</width> <width>14</width>
<height>18</height> <height>14</height>
</size> </size>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -450,8 +448,6 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>previewButton</tabstop> <tabstop>previewButton</tabstop>
<tabstop>topButton</tabstop>
<tabstop>bottomButton</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="../../../res.qrc"/> <include location="../../../res.qrc"/>