Commit 1ad918af authored by Alexander A. Maly's avatar Alexander A. Maly

Fixed "Сброк настроек" in menu and toolbar

parent 42b99b78
Pipeline #2934 passed with stages
in 4 minutes and 4 seconds
......@@ -1623,7 +1623,7 @@ p, li { white-space: pre-wrap; }
<message>
<location filename="../../../src/plugins/coregui/toolbarcontextmenu.cpp" line="88"/>
<source>Reset to default</source>
<translation>Сброк настроек отображения</translation>
<translation>Сброс настроек отображения</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/toolbarcontextmenu.cpp" line="89"/>
......
......@@ -10,8 +10,11 @@
#include <QDesktopWidget>
#include <QMenuBar>
#include <QToolBar>
#include <QGridLayout>
#include <QPushButton>
namespace CoreGUI {
namespace CoreGUI
{
static const int MaxColumns = 2;
......@@ -43,13 +46,13 @@ ToolbarContextMenu::ToolbarContextMenu(QWidget *parent)
void ToolbarContextMenu::addProxy(QAction *proxyItem)
{
items_.append(proxyItem);
QCheckBox * toggle = new QCheckBox(proxyItem->text(), this);
QCheckBox *toggle = new QCheckBox(proxyItem->text(), this);
toggle->setIcon(proxyItem->icon());
quintptr targetPtr = quintptr(proxyItem);
quintptr togglePtr = quintptr(toggle);
proxyItem->setProperty("toggle", togglePtr);
toggle->setProperty("target", targetPtr);
grid_->addWidget(toggle, currentRow_, currentColumn_, 1, 1, Qt::AlignLeft|Qt::AlignVCenter);
grid_->addWidget(toggle, currentRow_, currentColumn_, 1, 1, Qt::AlignLeft | Qt::AlignVCenter);
currentColumn_ ++;
if (currentColumn_ >= MaxColumns) {
currentRow_ ++;
......@@ -65,7 +68,7 @@ void ToolbarContextMenu::addSeparator()
currentRow_ ++;
currentColumn_ = 0;
}
QFrame * line = new QFrame(this);
QFrame *line = new QFrame(this);
line->setObjectName(QString::fromUtf8("line"));
line->setFixedHeight(3);
line->setMinimumWidth(480);
......@@ -81,8 +84,8 @@ void ToolbarContextMenu::addSeparator()
void ToolbarContextMenu::finalize()
{
addSeparator();
QWidget * box = new QWidget(this);
QHBoxLayout * l = new QHBoxLayout;
QWidget *box = new QWidget(this);
QHBoxLayout *l = new QHBoxLayout;
box->setLayout(l);
btnClose_ = new QPushButton(tr("Close"), this);
btnReset_ = new QPushButton(tr("Reset to default"), this);
......@@ -106,9 +109,9 @@ void ToolbarContextMenu::setExplicitImportNames(const QSet<QString> explicitItem
{
explicitImportNames_ = explicitItemNames;
ignoreStateChange_ = true;
Q_FOREACH(QAction* target, items_) {
Q_FOREACH (QAction *target, items_) {
quintptr togglePtr = target->property("toggle").toULongLong();
QCheckBox * toggle = reinterpret_cast<QCheckBox*>(togglePtr);
QCheckBox *toggle = reinterpret_cast<QCheckBox *>(togglePtr);
target->setVisible(isItemVisible(toggle->checkState(), target->objectName()));
}
saveSettings();
......@@ -117,11 +120,12 @@ void ToolbarContextMenu::setExplicitImportNames(const QSet<QString> explicitItem
void ToolbarContextMenu::toggleProxyButtonVisible(int iState)
{
if (ignoreStateChange_)
if (ignoreStateChange_) {
return;
}
Qt::CheckState state = Qt::CheckState(iState);
quintptr targetPtr = sender()->property("target").toULongLong();
Widgets::ActionProxy * target = reinterpret_cast<Widgets::ActionProxy*>(targetPtr);
Widgets::ActionProxy *target = reinterpret_cast<Widgets::ActionProxy *>(targetPtr);
target->setVisible(isItemVisible(state, target->objectName()));
saveSettings();
}
......@@ -145,14 +149,14 @@ Qt::CheckState ToolbarContextMenu::defaultVisible(const QString &objectName)
<< "menuRun" << "menuWindow" << "menuHelp"
<< "menu-CourseManager" << "menu-ActorRobot" << "menu-ActorDraw"
;
if (standardItems.contains(objectName))
if (standardItems.contains(objectName)) {
return Qt::Checked;
}
if (
objectName.startsWith("window-actor-") ||
objectName.startsWith("window-control-") ||
objectName.startsWith("menu-Actor")
)
{
) {
return Qt::PartiallyChecked;
}
return Qt::Unchecked;
......@@ -165,22 +169,25 @@ void ToolbarContextMenu::setSettingsObject(ExtensionSystem::SettingsPtr settings
loadSettings();
}
float ToolbarContextMenu::cs2f(const Qt::CheckState state) {
float ToolbarContextMenu::cs2f(const Qt::CheckState state)
{
switch (state) {
case Qt::PartiallyChecked: return 0.5f;
case Qt::Checked: return 1.0f;
default: return 0.0f;
case Qt::PartiallyChecked:
return 0.5f;
case Qt::Checked:
return 1.0f;
default:
return 0.0f;
}
}
Qt::CheckState ToolbarContextMenu::f2cs(const float value) {
Qt::CheckState ToolbarContextMenu::f2cs(const float value)
{
if (value > 0.9f) {
return Qt::Checked;
}
else if (0.4f < value && value < 0.6f) {
} else if (0.4f < value && value < 0.6f) {
return Qt::PartiallyChecked;
}
else {
} else {
return Qt::Unchecked;
}
}
......@@ -188,13 +195,14 @@ Qt::CheckState ToolbarContextMenu::f2cs(const float value) {
void ToolbarContextMenu::loadSettings()
{
ignoreStateChange_ = true;
if (!settings_) return;
Q_FOREACH(QAction * target, items_) {
if (!settings_) {
return;
}
Q_FOREACH (QAction *target, items_) {
quintptr togglePtr = target->property("toggle").toULongLong();
QCheckBox * toggle = reinterpret_cast<QCheckBox*>(togglePtr);
QCheckBox *toggle = reinterpret_cast<QCheckBox *>(togglePtr);
if (target->objectName().startsWith("window-actor-") ||
target->objectName().startsWith("window-control-"))
{
target->objectName().startsWith("window-control-")) {
toggle->setTristate(true);
}
const QString key = settingsPrefix_ + "/" + (
......@@ -214,10 +222,12 @@ void ToolbarContextMenu::loadSettings()
void ToolbarContextMenu::saveSettings() const
{
if (!settings_) return;
Q_FOREACH(QAction * target, items_) {
if (!settings_) {
return;
}
Q_FOREACH (QAction *target, items_) {
quintptr togglePtr = target->property("toggle").toULongLong();
QCheckBox * toggle = reinterpret_cast<QCheckBox*>(togglePtr);
QCheckBox *toggle = reinterpret_cast<QCheckBox *>(togglePtr);
const QString key = settingsPrefix_ + "/" + (
target->objectName().isEmpty()
? QString("unknown")
......@@ -231,9 +241,9 @@ void ToolbarContextMenu::saveSettings() const
void ToolbarContextMenu::reset()
{
ignoreStateChange_ = true;
Q_FOREACH(QAction * target, items_) {
Q_FOREACH (QAction *target, items_) {
quintptr togglePtr = target->property("toggle").toULongLong();
QCheckBox * toggle = reinterpret_cast<QCheckBox*>(togglePtr);
QCheckBox *toggle = reinterpret_cast<QCheckBox *>(togglePtr);
toggle->setCheckState(defaultVisible(target->objectName()));
target->setVisible(isItemVisible(toggle->checkState(), target->objectName()));
}
......@@ -251,9 +261,9 @@ bool ToolbarContextMenu::isItemVisible(Qt::CheckState state, const QString &obje
void ToolbarContextMenu::showAll()
{
ignoreStateChange_ = true;
Q_FOREACH(QAction * target, items_) {
Q_FOREACH (QAction *target, items_) {
quintptr togglePtr = target->property("toggle").toULongLong();
QCheckBox * toggle = reinterpret_cast<QCheckBox*>(togglePtr);
QCheckBox *toggle = reinterpret_cast<QCheckBox *>(togglePtr);
toggle->setCheckState(Qt::Checked);
target->setVisible(true);
}
......@@ -276,9 +286,9 @@ void ToolbarContextMenu::paintEvent(QPaintEvent *event)
const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this);
QRegion borderReg;
borderReg += QRect(0, 0, fw, height()); //left
borderReg += QRect(width()-fw, 0, fw, height()); //right
borderReg += QRect(width() - fw, 0, fw, height()); //right
borderReg += QRect(0, 0, width(), fw); //top
borderReg += QRect(0, height()-fw, width(), fw); //bottom
borderReg += QRect(0, height() - fw, width(), fw); //bottom
p.setClipRegion(borderReg);
emptyArea -= borderReg;
QStyleOptionFrame frame;
......@@ -292,8 +302,8 @@ void ToolbarContextMenu::paintEvent(QPaintEvent *event)
void ToolbarContextMenu::showMe()
{
QWidget * widget = 0;
QList<QWidget*> widgets = showAction()->associatedWidgets();
QWidget *widget = 0;
QList<QWidget *> widgets = showAction()->associatedWidgets();
if (widgets.size() > 0) {
widget = widgets.at(0);
}
......@@ -301,38 +311,36 @@ void ToolbarContextMenu::showMe()
QPoint position;
if (widget) {
QMenuBar * mb = qobject_cast<QMenuBar*>(widget);
QToolBar * tb = qobject_cast<QToolBar*>(widget);
QMenuBar *mb = qobject_cast<QMenuBar *>(widget);
QToolBar *tb = qobject_cast<QToolBar *>(widget);
if (mb) {
position = mb->mapToGlobal(mb->pos());
position.ry() += mb->height();
for (int x=0; x<mb->width(); x++) {
QAction * a = mb->actionAt(QPoint(x, mb->height()/2));
for (int x = 0; x < mb->width(); x++) {
QAction *a = mb->actionAt(QPoint(x, mb->height() / 2));
if (showAction() == a) {
position.rx() += x;
break;
}
}
}
else if (tb) {
} else if (tb) {
position = tb->mapToGlobal(tb->pos());
position.ry() += tb->height();
for (int x=0; x<tb->width(); x++) {
QAction * a = tb->actionAt(QPoint(x, tb->height()/2));
for (int x = 0; x < tb->width(); x++) {
QAction *a = tb->actionAt(QPoint(x, tb->height() / 2));
if (showAction() == a) {
position.rx() += x;
break;
}
}
}
else {
} else {
position = widget->pos();
}
}
QRect contextRect(position, size());
QDesktopWidget* screen = qApp->desktop();
const QRect screenRect = screen->availableGeometry(this);
QDesktopWidget *screen = qApp->desktop();
QRect screenRect = screen->availableGeometry(this);
if (contextRect.right() > screenRect.right()) {
contextRect.moveRight(screenRect.right());
}
......
......@@ -5,33 +5,37 @@
#include <kumir2-libs/extensionsystem/settings.h>
#include <QWidget>
#include <QGridLayout>
#include <QPushButton>
#include <QSet>
class QGridLayout;
class QPushButton;
namespace CoreGUI {
namespace CoreGUI
{
class ToolbarContextMenu : public QWidget
{
Q_OBJECT
public:
explicit ToolbarContextMenu(QWidget *parent = 0);
void addProxy(QAction * proxyItem);
void addProxy(QAction *proxyItem);
void addSeparator();
void finalize();
void setSettingsObject(ExtensionSystem::SettingsPtr settings, const QString &settingsPrefix);
void setExplicitImportNames(const QSet<QString> explicitItemNames);
inline QAction * showAction() const { return showAction_; }
QAction *showAction() const
{
return showAction_;
}
void saveSettings() const;
void loadSettings();
static Qt::CheckState defaultVisible(const QString & objectName);
static Qt::CheckState defaultVisible(const QString &objectName);
static Qt::CheckState f2cs(float value);
static float cs2f(Qt::CheckState state);
bool isItemVisible(Qt::CheckState state, const QString & objectName) const;
bool isItemVisible(Qt::CheckState state, const QString &objectName) const;
protected Q_SLOTS:
......@@ -41,22 +45,22 @@ protected Q_SLOTS:
void showMe();
protected:
void showEvent(QShowEvent * event);
void showEvent(QShowEvent *event);
void paintEvent(QPaintEvent *event);
QList<QAction*> items_;
QList<QAction *> items_;
QSet<QString> forcedItemNames_;
QGridLayout * grid_;
QGridLayout *grid_;
int currentRow_;
int currentColumn_;
QPushButton * btnClose_;
QPushButton * btnReset_;
QPushButton * btnShowAll_;
QPushButton *btnClose_;
QPushButton *btnReset_;
QPushButton *btnShowAll_;
ExtensionSystem::SettingsPtr settings_;
QString settingsPrefix_;
QSet<QString> explicitImportNames_;
bool ignoreStateChange_;
QAction* showAction_;
QAction *showAction_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment