-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1461 from 1445643474/master
optimize toolmenubutton style
- Loading branch information
Showing
16 changed files
with
173 additions
and
81 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,43 @@ | ||
#include "ztoolmenubutton.h" | ||
#include "../style/zstyleoption.h" | ||
#include "../style/zenostyle.h" | ||
|
||
ZToolMenuButton::ZToolMenuButton(QWidget* parent) | ||
: ZToolButton(parent) | ||
{ | ||
setButtonOptions(ZToolButton::Opt_TextRightToIcon); | ||
setArrowOption(ZStyleOptionToolButton::DOWNARROW); | ||
setBorderColor(QColor(255,255,255,102)); | ||
m_pMenu = new QMenu(this); | ||
m_pMenu->setProperty("cssClass", "menuButton"); | ||
} | ||
|
||
void ZToolMenuButton::addAction(const QString& action, const QString& icon) | ||
{ | ||
QAction* pAction = new QAction(QIcon(icon), action, this); | ||
connect(pAction, &QAction::triggered, this, [=]() { | ||
setText(action); | ||
this->setMinimumWidth(sizeHint().width()); | ||
emit textChanged(); | ||
}); | ||
m_pMenu->addAction(pAction); | ||
} | ||
|
||
void ZToolMenuButton::mouseReleaseEvent(QMouseEvent* e) { | ||
QSize size = ZToolButton::sizeHint(); | ||
if (e->x() >= (size.width() - ZenoStyle::dpiScaled(10))) | ||
{ | ||
QPoint pos; | ||
pos.setY(pos.y() + this->geometry().height()); | ||
m_pMenu->exec(this->mapToGlobal(pos)); | ||
return; | ||
} | ||
emit clicked(); | ||
} | ||
|
||
|
||
QSize ZToolMenuButton::sizeHint() const { | ||
QSize size = ZToolButton::sizeHint(); | ||
size.setWidth(size.width() + ZenoStyle::dpiScaled(12)); | ||
return size; | ||
} |
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,23 @@ | ||
#ifndef __ZTOOLMENUBUTTON_H__ | ||
#define __ZTOOLMENUBUTTON_H__ | ||
|
||
class ZStyleOptionToolButton; | ||
|
||
#include <QtWidgets> | ||
#include "ztoolbutton.h" | ||
|
||
class ZToolMenuButton : public ZToolButton { | ||
Q_OBJECT | ||
public: | ||
ZToolMenuButton(QWidget *parent = nullptr); | ||
void addAction(const QString& action, const QString& icon = ""); | ||
signals: | ||
void textChanged(); | ||
protected: | ||
virtual void mouseReleaseEvent(QMouseEvent* e) override; | ||
virtual QSize sizeHint() const override; | ||
private: | ||
QMenu* m_pMenu; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.