Moved menu separator to separate file.
This commit is contained in:
parent
8d5bdd6b7e
commit
7e52011a06
5 changed files with 90 additions and 51 deletions
|
|
@ -151,6 +151,8 @@ PRIVATE
|
||||||
ui/widgets/menu/menu_common.h
|
ui/widgets/menu/menu_common.h
|
||||||
ui/widgets/menu/menu_item_base.cpp
|
ui/widgets/menu/menu_item_base.cpp
|
||||||
ui/widgets/menu/menu_item_base.h
|
ui/widgets/menu/menu_item_base.h
|
||||||
|
ui/widgets/menu/menu_separator.cpp
|
||||||
|
ui/widgets/menu/menu_separator.h
|
||||||
ui/widgets/popup_menu.cpp
|
ui/widgets/popup_menu.cpp
|
||||||
ui/widgets/popup_menu.h
|
ui/widgets/popup_menu.h
|
||||||
ui/widgets/scroll_area.cpp
|
ui/widgets/scroll_area.cpp
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/menu/menu_item_base.h"
|
#include "ui/widgets/menu/menu_item_base.h"
|
||||||
|
#include "ui/widgets/menu/menu_separator.h"
|
||||||
#include "ui/text/text.h"
|
#include "ui/text/text.h"
|
||||||
|
|
||||||
#include <QtGui/QtEvents>
|
#include <QtGui/QtEvents>
|
||||||
|
|
@ -51,55 +52,6 @@ TextParseOptions MenuTextOptions = {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class Menu::Separator : public ItemBase {
|
|
||||||
public:
|
|
||||||
Separator(not_null<RpWidget*> parent, const style::Menu &st, int index)
|
|
||||||
: ItemBase(parent, st, index)
|
|
||||||
, _lineWidth(st.separatorWidth)
|
|
||||||
, _padding(st.separatorPadding)
|
|
||||||
, _fg(st.separatorFg)
|
|
||||||
, _bg(st.itemBg)
|
|
||||||
, _height(_padding.top() + _lineWidth + _padding.bottom()) {
|
|
||||||
|
|
||||||
initResizeHook(parent->sizeValue());
|
|
||||||
// setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
paintRequest(
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
Painter p(this);
|
|
||||||
|
|
||||||
p.fillRect(0, 0, width(), _height, _bg);
|
|
||||||
p.fillRect(
|
|
||||||
_padding.left(),
|
|
||||||
_padding.top(),
|
|
||||||
width() - _padding.left() - _padding.right(),
|
|
||||||
_lineWidth,
|
|
||||||
_fg);
|
|
||||||
}, lifetime());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QAction *action() const override {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isEnabled() const override {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int contentHeight() const override {
|
|
||||||
return _height;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const int _lineWidth;
|
|
||||||
const style::margins &_padding;
|
|
||||||
const style::color &_fg;
|
|
||||||
const style::color &_bg;
|
|
||||||
const int _height;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Menu::Action : public ItemBase {
|
class Menu::Action : public ItemBase {
|
||||||
public:
|
public:
|
||||||
Action(
|
Action(
|
||||||
|
|
@ -329,7 +281,7 @@ not_null<QAction*> Menu::addAction(not_null<QAction*> action, const style::icon
|
||||||
: _actionWidgets.back()->y() + _actionWidgets.back()->height();
|
: _actionWidgets.back()->y() + _actionWidgets.back()->height();
|
||||||
const auto index = _actionWidgets.size();
|
const auto index = _actionWidgets.size();
|
||||||
if (action->isSeparator()) {
|
if (action->isSeparator()) {
|
||||||
auto widget = base::make_unique_q<Separator>(this, _st, index);
|
auto widget = base::make_unique_q<Ui::Separator>(this, _st, index);
|
||||||
widget->moveToLeft(0, top);
|
widget->moveToLeft(0, top);
|
||||||
widget->show();
|
widget->show();
|
||||||
_actionWidgets.push_back(std::move(widget));
|
_actionWidgets.push_back(std::move(widget));
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Separator;
|
|
||||||
class Action;
|
class Action;
|
||||||
|
|
||||||
void updateSelected(QPoint globalPosition);
|
void updateSelected(QPoint globalPosition);
|
||||||
|
|
|
||||||
51
ui/widgets/menu/menu_separator.cpp
Normal file
51
ui/widgets/menu/menu_separator.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
// 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/menu/menu_separator.h"
|
||||||
|
|
||||||
|
#include "ui/painter.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
Separator::Separator(
|
||||||
|
not_null<RpWidget*> parent,
|
||||||
|
const style::Menu &st,
|
||||||
|
int index)
|
||||||
|
: ItemBase(parent, st, index)
|
||||||
|
, _lineWidth(st.separatorWidth)
|
||||||
|
, _padding(st.separatorPadding)
|
||||||
|
, _fg(st.separatorFg)
|
||||||
|
, _bg(st.itemBg)
|
||||||
|
, _height(_padding.top() + _lineWidth + _padding.bottom()) {
|
||||||
|
|
||||||
|
initResizeHook(parent->sizeValue());
|
||||||
|
paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
Painter p(this);
|
||||||
|
|
||||||
|
p.fillRect(0, 0, width(), _height, _bg);
|
||||||
|
p.fillRect(
|
||||||
|
_padding.left(),
|
||||||
|
_padding.top(),
|
||||||
|
width() - _padding.left() - _padding.right(),
|
||||||
|
_lineWidth,
|
||||||
|
_fg);
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *Separator::action() const {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Separator::isEnabled() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Separator::contentHeight() const {
|
||||||
|
return _height;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ui
|
||||||
35
ui/widgets/menu/menu_separator.h
Normal file
35
ui/widgets/menu/menu_separator.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
// 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/menu/menu_item_base.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
|
class Painter;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
class Separator : public ItemBase {
|
||||||
|
public:
|
||||||
|
Separator(not_null<RpWidget*> parent, const style::Menu &st, int index);
|
||||||
|
|
||||||
|
QAction *action() const override;
|
||||||
|
bool isEnabled() const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int contentHeight() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int _lineWidth;
|
||||||
|
const style::margins &_padding;
|
||||||
|
const style::color &_fg;
|
||||||
|
const style::color &_bg;
|
||||||
|
const int _height;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Ui
|
||||||
Loading…
Add table
Reference in a new issue