2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Move standard buttons to lib_ui.

This commit is contained in:
John Preston
2019-09-13 19:45:48 +03:00
parent a16c6ca41a
commit c057f28425
45 changed files with 330 additions and 150 deletions

View File

@@ -11,9 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/cross_animation.h"
#include "ui/effects/numbers_animation.h"
#include "ui/image/image_prepare.h"
#include "window/themes/window_theme.h"
#include "lang/lang_instance.h"
#include "app.h"
#include "ui/painter.h"
namespace Ui {
@@ -91,13 +89,11 @@ void RippleButton::setForceRippled(
if (_forceRippled != rippled) {
_forceRippled = rippled;
if (_forceRippled) {
_forceRippledSubscription = base::ObservableViewer(
*Window::Theme::Background()
) | rpl::start_with_next([=](
const Window::Theme::BackgroundUpdate &update) {
if (update.paletteChanged() && _ripple) {
_ripple->forceRepaint();
}
_forceRippledSubscription = style::PaletteChanged(
) | rpl::filter([=] {
return _ripple != nullptr;
}) | rpl::start_with_next([=] {
_ripple->forceRepaint();
});
ensureRipple();
if (_ripple->empty()) {
@@ -350,7 +346,12 @@ void RoundButton::paintEvent(QPaintEvent *e) {
p.setBrush(color);
p.drawRoundedRect(fill, radius, radius);
} else {
App::roundRect(p, fill, color, ImageRoundRadius::Small);
PainterHighQualityEnabler hq(p);
p.setPen(Qt::NoPen);
p.setBrush(color);
p.drawRoundedRect(fill, st::buttonRadius, st::buttonRadius);
// #TODO ui
//App::roundRect(p, fill, color, ImageRoundRadius::Small);
}
};
drawRect(_st.textBg);

View File

@@ -101,7 +101,7 @@ private:
};
class RoundButton : public RippleButton, private base::Subscriber {
class RoundButton : public RippleButton {
public:
RoundButton(
QWidget *parent,

View File

@@ -13,7 +13,7 @@ namespace Ui {
DropdownMenu::DropdownMenu(QWidget *parent, const style::DropdownMenu &st) : InnerDropdown(parent, st.wrap)
, _st(st) {
_menu = setOwnedWidget(object_ptr<Ui::Menu>(this, _st.menu));
_menu = setOwnedWidget(object_ptr<Menu>(this, _st.menu));
init();
}

View File

@@ -52,10 +52,18 @@ InnerDropdown::InnerDropdown(
}, lifetime());
}
QPointer<TWidget> InnerDropdown::doSetOwnedWidget(object_ptr<TWidget> widget) {
auto result = QPointer<TWidget>(widget);
connect(widget, SIGNAL(heightUpdated()), this, SLOT(onWidgetHeightUpdated()));
auto container = _scroll->setOwnedWidget(object_ptr<Container>(_scroll, std::move(widget), _st));
QPointer<RpWidget> InnerDropdown::doSetOwnedWidget(
object_ptr<RpWidget> widget) {
auto result = QPointer<RpWidget>(widget);
widget->heightValue(
) | rpl::skip(1) | rpl::start_with_next([=] {
resizeToContent();
}, widget->lifetime());
auto container = _scroll->setOwnedWidget(
object_ptr<Container>(
_scroll,
std::move(widget),
_st));
container->resizeToWidth(_scroll->width());
container->moveToLeft(0, 0);
container->show();

View File

@@ -86,12 +86,9 @@ private slots:
hideAnimated();
}
void onScroll();
void onWidgetHeightUpdated() {
resizeToContent();
}
private:
QPointer<TWidget> doSetOwnedWidget(object_ptr<TWidget> widget);
QPointer<RpWidget> doSetOwnedWidget(object_ptr<RpWidget> widget);
QImage grabForPanelAnimation();
void startShowAnimation();
void startOpacityAnimation(bool hiding);

View File

@@ -24,14 +24,16 @@ struct Menu::ActionData {
bool hasSubmenu = false;
};
Menu::Menu(QWidget *parent, const style::Menu &st) : TWidget(parent)
Menu::Menu(QWidget *parent, const style::Menu &st)
: RpWidget(parent)
, _st(st)
, _itemHeight(_st.itemPadding.top() + _st.itemStyle.font->height + _st.itemPadding.bottom())
, _separatorHeight(_st.separatorPadding.top() + _st.separatorWidth + _st.separatorPadding.bottom()) {
init();
}
Menu::Menu(QWidget *parent, QMenu *menu, const style::Menu &st) : TWidget(parent)
Menu::Menu(QWidget *parent, QMenu *menu, const style::Menu &st)
: RpWidget(parent)
, _st(st)
, _wappedMenu(menu)
, _itemHeight(_st.itemPadding.top() + _st.itemStyle.font->height + _st.itemPadding.bottom())
@@ -68,7 +70,9 @@ not_null<QAction*> Menu::addAction(const QString &text, Fn<void()> callback, con
}
not_null<QAction*> Menu::addAction(not_null<QAction*> action, const style::icon *icon, const style::icon *iconOver) {
connect(action, SIGNAL(changed()), this, SLOT(actionChanged()));
connect(action, &QAction::changed, this, [=] {
actionChanged();
});
_actions.emplace_back(action);
_actionsData.push_back([&] {
auto data = ActionData();

View File

@@ -17,9 +17,7 @@ namespace Ui {
class ToggleView;
class RippleAnimation;
class Menu : public TWidget {
Q_OBJECT
class Menu : public RpWidget {
public:
Menu(QWidget *parent, const style::Menu &st = st::defaultMenu);
Menu(QWidget *parent, QMenu *menu, const style::Menu &st = st::defaultMenu);
@@ -85,13 +83,11 @@ protected:
void enterEventHook(QEvent *e) override;
void leaveEventHook(QEvent *e) override;
private slots:
void actionChanged();
private:
struct ActionData;
void updateSelected(QPoint globalPosition);
void actionChanged();
void init();
// Returns the new width.

View File

@@ -9,12 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "platform/platform_specific.h"
#include "core/qt_signal_producer.h"
#include "ui/ui_utility.h"
#include "app.h"
#include "styles/style_widgets.h"
#include <QtCore/QCoreApplication>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
namespace Ui {