-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace SideBarMenu with SideBarButton.
- Loading branch information
1 parent
15af905
commit 1b673b7
Showing
6 changed files
with
197 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// This file is part of Desktop App Toolkit, | ||
// a set of libraries for developing nice desktop applications. | ||
// | ||
// For license and copyright information please follow this link: | ||
// https://github.com/desktop-app/legal/blob/master/LEGAL | ||
// | ||
#include "ui/widgets/side_bar_button.h" | ||
|
||
#include "ui/effects/ripple_animation.h" | ||
|
||
#include <QtGui/QtEvents> | ||
|
||
namespace Ui { | ||
namespace { | ||
|
||
constexpr auto kMaxLabelLines = 3; | ||
|
||
} // namespace | ||
|
||
SideBarButton::SideBarButton( | ||
not_null<QWidget*> parent, | ||
const QString &title, | ||
const style::SideBarButton &st) | ||
: RippleButton(parent, st.ripple) | ||
, _st(st) | ||
, _text(_st.minTextWidth) { | ||
_text.setText(_st.style, title); | ||
setAttribute(Qt::WA_OpaquePaintEvent); | ||
} | ||
|
||
void SideBarButton::setActive(bool active) { | ||
if (_active == active) { | ||
return; | ||
} | ||
_active = active; | ||
update(); | ||
} | ||
|
||
void SideBarButton::setBadge(const QString &badge) { | ||
if (_badge.toString() == badge) { | ||
return; | ||
} | ||
_badge.setText(_st.badgeStyle, badge); | ||
update(); | ||
} | ||
|
||
int SideBarButton::resizeGetHeight(int newWidth) { | ||
auto result = _st.minHeight; | ||
const auto text = _text.countHeight(newWidth - _st.textSkip * 2); | ||
const auto add = text - _st.style.font->height; | ||
return result + std::max(add, 0); | ||
} | ||
|
||
void SideBarButton::paintEvent(QPaintEvent *e) { | ||
auto p = Painter(this); | ||
const auto clip = e->rect(); | ||
|
||
p.fillRect(clip, _active ? _st.textBgActive : _st.textBg); | ||
|
||
RippleButton::paintRipple(p, 0, 0); | ||
|
||
const auto &icon = _active ? _st.iconActive : _st.icon; | ||
const auto x = (_st.iconPosition.x() < 0) | ||
? (width() - icon.width()) / 2 | ||
: _st.iconPosition.x(); | ||
const auto y = (_st.iconPosition.y() < 0) | ||
? (height() - icon.height()) / 2 | ||
: _st.iconPosition.y(); | ||
icon.paint(p, x, y, width()); | ||
p.setPen(_active ? _st.textFgActive : _st.textFg); | ||
_text.drawElided( | ||
p, | ||
_st.textSkip, | ||
_st.textTop, | ||
(width() - 2 * _st.textSkip), | ||
kMaxLabelLines, | ||
style::al_top); | ||
} | ||
|
||
} // namespace Ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// This file is part of Desktop App Toolkit, | ||
// a set of libraries for developing nice desktop applications. | ||
// | ||
// For license and copyright information please follow this link: | ||
// https://github.com/desktop-app/legal/blob/master/LEGAL | ||
// | ||
#pragma once | ||
|
||
#include "ui/widgets/buttons.h" | ||
#include "ui/text/text.h" | ||
|
||
namespace style { | ||
struct SideBarButton; | ||
} // namespace style | ||
|
||
namespace Ui { | ||
|
||
class RippleAnimation; | ||
|
||
class SideBarButton final : public Ui::RippleButton { | ||
public: | ||
SideBarButton( | ||
not_null<QWidget*> parent, | ||
const QString &title, | ||
const style::SideBarButton &st); | ||
|
||
void setActive(bool active); | ||
void setBadge(const QString &badge); | ||
|
||
int resizeGetHeight(int newWidth) override; | ||
|
||
private: | ||
void paintEvent(QPaintEvent *e) override; | ||
|
||
const style::SideBarButton &_st; | ||
Ui::Text::String _text; | ||
Ui::Text::String _badge; | ||
bool _active = false; | ||
|
||
}; | ||
// | ||
//class SideBarMenu final { | ||
//public: | ||
// struct Item { | ||
// QString id; | ||
// QString title; | ||
// QString badge; | ||
// not_null<const style::icon*> icon; | ||
// not_null<const style::icon*> iconActive; | ||
// int iconTop = 0; | ||
// }; | ||
// | ||
// SideBarMenu(not_null<QWidget*> parent, const style::SideBarMenu &st); | ||
// ~SideBarMenu(); | ||
// | ||
// [[nodiscard]] not_null<const Ui::RpWidget*> widget() const; | ||
// | ||
// void setGeometry(QRect geometry); | ||
// void setItems(std::vector<Item> items); | ||
// void setActive( | ||
// const QString &id, | ||
// anim::type animated = anim::type::normal); | ||
// [[nodiscard]] rpl::producer<QString> activateRequests() const; | ||
// | ||
// [[nodiscard]] rpl::lifetime &lifetime(); | ||
// | ||
//private: | ||
// struct MenuItem { | ||
// Item data; | ||
// Ui::Text::String text; | ||
// mutable std::unique_ptr<Ui::RippleAnimation> ripple; | ||
// int top = 0; | ||
// int height = 0; | ||
// }; | ||
// void setup(); | ||
// void paint(Painter &p, QRect clip) const; | ||
// [[nodiscard]] int countContentHeight(int width, int outerHeight); | ||
// | ||
// void mouseMove(QPoint position); | ||
// void mousePress(Qt::MouseButton button); | ||
// void mouseRelease(Qt::MouseButton button); | ||
// | ||
// void setSelected(int selected); | ||
// void setPressed(int pressed); | ||
// void addRipple(MenuItem &item, QPoint position); | ||
// void repaint(const QString &id); | ||
// [[nodiscard]] MenuItem *itemById(const QString &id); | ||
// | ||
// const style::SideBarMenu &_st; | ||
// | ||
// Ui::RpWidget _outer; | ||
// const not_null<Ui::ScrollArea*> _scroll; | ||
// const not_null<Ui::RpWidget*> _inner; | ||
// std::vector<MenuItem> _items; | ||
// int _selected = -1; | ||
// int _pressed = -1; | ||
// | ||
// QString _activeId; | ||
// rpl::event_stream<QString> _activateRequests; | ||
// | ||
//}; | ||
|
||
} // namespace Ui |
Oops, something went wrong.