added the update download button for linux/mac (updates don't work tho

so it doesn't show)
This commit is contained in:
fourtf 2018-07-05 13:25:10 +02:00
parent 59332270b5
commit 3d7926cac1
4 changed files with 102 additions and 70 deletions

View file

@ -12,6 +12,8 @@ void initUpdateButton(RippleEffectButton &button, std::unique_ptr<UpdatePromptDi
// show update prompt when clicking the button
QObject::connect(&button, &RippleEffectButton::clicked, [&button, &handle] {
(void)(handle);
auto dialog = new UpdatePromptDialog();
dialog->setActionOnFocusLoss(BaseWindow::Delete);
dialog->move(button.mapToGlobal(QPoint(int(-100 * button.getScale()), button.height())));
@ -26,8 +28,10 @@ void initUpdateButton(RippleEffectButton &button, std::unique_ptr<UpdatePromptDi
}
});
#ifdef Q_OS_WIN
handle.reset(dialog);
dialog->closing.connect([&handle] { handle.release(); });
#endif
});
// update image when state changes

View file

@ -304,8 +304,6 @@ void Notebook::resizeEvent(QResizeEvent *)
void Notebook::performLayout(bool animated)
{
auto app = getApp();
int xStart = int(2 * this->getScale());
int x = xStart, y = 0;
@ -409,8 +407,6 @@ NotebookTab *Notebook::getTabFromPage(QWidget *page)
SplitNotebook::SplitNotebook(Window *parent)
: Notebook(parent)
{
auto app = getApp();
this->connect(this->getAddButton(), &NotebookButton::clicked,
[this]() { QTimer::singleShot(80, this, [this] { this->addPage(true); }); });
@ -429,13 +425,10 @@ void SplitNotebook::addCustomButtons()
settingsBtn->setVisible(!getApp()->settings->hidePreferencesButton.getValue());
getApp()->settings->hidePreferencesButton.connect(
[this, settingsBtn](bool hide, auto) {
settingsBtn->setVisible(!hide);
this->performLayout(true);
},
[settingsBtn](bool hide, auto) { settingsBtn->setVisible(!hide); },
this->uniqueConnections);
settingsBtn->icon = NotebookButton::IconSettings;
settingsBtn->setIcon(NotebookButton::Settings);
QObject::connect(settingsBtn, &NotebookButton::clicked,
[] { getApp()->windows->showSettingsDialog(); });
@ -444,13 +437,9 @@ void SplitNotebook::addCustomButtons()
auto userBtn = this->addCustomButton();
userBtn->setVisible(!getApp()->settings->hideUserButton.getValue());
getApp()->settings->hideUserButton.connect(
[this, userBtn](bool hide, auto) {
userBtn->setVisible(!hide);
this->performLayout(true);
},
this->uniqueConnections);
[userBtn](bool hide, auto) { userBtn->setVisible(!hide); }, this->uniqueConnections);
userBtn->icon = NotebookButton::IconUser;
userBtn->setIcon(NotebookButton::User);
QObject::connect(userBtn, &NotebookButton::clicked, [this, userBtn] {
getApp()->windows->showAccountSelectPopup(this->mapToGlobal(userBtn->rect().bottomRight()));
});

View file

@ -13,18 +13,31 @@
namespace chatterino {
NotebookButton::NotebookButton(BaseWidget *parent)
NotebookButton::NotebookButton(Notebook *parent)
: RippleEffectButton(parent)
, parent_(parent)
{
this->setAcceptDrops(true);
}
void NotebookButton::setIcon(Icon icon)
{
this->icon_ = icon;
this->update();
}
NotebookButton::Icon NotebookButton::getIcon() const
{
return this->icon_;
}
void NotebookButton::themeRefreshEvent()
{
this->setMouseEffectColor(this->themeManager->tabs.regular.text);
}
void NotebookButton::paintEvent(QPaintEvent *)
void NotebookButton::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
@ -43,60 +56,70 @@ void NotebookButton::paintEvent(QPaintEvent *)
float h = height(), w = width();
if (icon == IconPlus) {
painter.setPen([&] {
QColor tmp = foreground;
if (!this->mouseOver_) {
tmp.setAlpha(180);
switch (icon_) {
case Plus: {
painter.setPen([&] {
QColor tmp = foreground;
if (!this->mouseOver_) {
tmp.setAlpha(180);
}
return tmp;
}());
QRect rect = this->rect();
int s = h * 4 / 9;
painter.drawLine(
rect.left() + rect.width() / 2 - (s / 2), rect.top() + rect.height() / 2,
rect.left() + rect.width() / 2 + (s / 2), rect.top() + rect.height() / 2);
painter.drawLine(
rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 - (s / 2),
rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 + (s / 2));
} break;
case User: {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = w / 8;
QPainterPath path;
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
painter.fillPath(path, foreground);
painter.setBrush(background);
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
painter.setBrush(foreground);
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
} break;
case Settings: {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = w / 8;
QPainterPath path;
path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
for (int i = 0; i < 8; i++) {
path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0), (360 / 32.0));
path.arcTo(2 * a, 2 * a, 4 * a, 4 * a, i * (360 / 8.0) + (360 / 32.0),
(360 / 32.0));
}
return tmp;
}());
QRect rect = this->rect();
int s = h * 4 / 9;
painter.drawLine(rect.left() + rect.width() / 2 - (s / 2), rect.top() + rect.height() / 2,
rect.left() + rect.width() / 2 + (s / 2), rect.top() + rect.height() / 2);
painter.drawLine(rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 - (s / 2),
rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 + (s / 2));
} else if (icon == IconUser) {
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.fillPath(path, foreground);
auto a = w / 8;
QPainterPath path;
painter.setBrush(background);
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
} break;
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
painter.fillPath(path, foreground);
painter.setBrush(background);
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
painter.setBrush(foreground);
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
} else // IconSettings
{
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
auto a = w / 8;
QPainterPath path;
path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
for (int i = 0; i < 8; i++) {
path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0), (360 / 32.0));
path.arcTo(2 * a, 2 * a, 4 * a, 4 * a, i * (360 / 8.0) + (360 / 32.0), (360 / 32.0));
}
painter.fillPath(path, foreground);
painter.setBrush(background);
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
default:;
}
fancyPaint(painter);
RippleEffectButton::paintEvent(event);
}
void NotebookButton::mouseReleaseEvent(QMouseEvent *event)
@ -157,4 +180,14 @@ void NotebookButton::dropEvent(QDropEvent *event)
}
}
void NotebookButton::hideEvent(QHideEvent *)
{
this->parent_->performLayout();
}
void NotebookButton::showEvent(QShowEvent *)
{
this->parent_->performLayout();
}
} // namespace chatterino

View file

@ -6,18 +6,19 @@
namespace chatterino {
class Notebook;
class NotebookButton : public RippleEffectButton
{
Q_OBJECT
public:
static const int IconPlus = 0;
static const int IconUser = 1;
static const int IconSettings = 2;
enum Icon { None, Plus, User, Settings };
int icon = 0;
explicit NotebookButton(Notebook *parent);
NotebookButton(BaseWidget *parent);
void setIcon(Icon icon_);
Icon getIcon() const;
protected:
virtual void themeRefreshEvent() override;
@ -27,11 +28,16 @@ protected:
virtual void dragLeaveEvent(QDragLeaveEvent *) override;
virtual void dropEvent(QDropEvent *) override;
virtual void hideEvent(QHideEvent *) override;
virtual void showEvent(QShowEvent *) override;
signals:
void clicked();
private:
Notebook *parent_ = nullptr;
QPoint mousePos_;
Icon icon_ = None;
};
} // namespace chatterino