added support for checkable items in nstoolbar //TODO find a better UI desing?

This commit is contained in:
Luis Ángel San Martín 2014-11-09 21:40:52 +01:00
parent d03fc902a1
commit 1ae1f04eb7
2 changed files with 55 additions and 0 deletions

View File

@ -29,6 +29,23 @@ signals:
void filterChanged(YACReader::SearchModifiers, QString);
};
class MacToolBarItemWrapper : public QObject
{
Q_OBJECT
public:
MacToolBarItemWrapper(QAction * action, QMacToolBarItem * toolbaritem);
public slots:
void actionToggled(bool toogled);
private:
QAction * action;
QMacToolBarItem * toolbaritem;
void updateIcon(bool checked);
};
class YACReaderMacOSXToolbar : public QMacToolBar
{
Q_OBJECT

View File

@ -190,8 +190,12 @@ void YACReaderMacOSXToolbar::addAction(QAction *action)
if(action->data().toString() == TOGGLE_COMICS_VIEW_ACTION_YL)
viewSelector = toolBarItem;
connect(toolBarItem,SIGNAL(activated()),action, SIGNAL(triggered()));
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
actions.insert(QString::fromNSString(nativeItem.itemIdentifier),action);
MacToolBarItemWrapper * wrapper = new MacToolBarItemWrapper(action,toolBarItem);
//wrapper->actionToogled(true);
}
void YACReaderMacOSXToolbar::addDropDownItem(const QList<QAction *> &actions, const QAction *defaultAction)
@ -325,3 +329,37 @@ void YACReaderMacOSXSearchLineEdit::setEnabled(bool enabled)
{
[((NSTextField *)nstextfield) setEnabled:enabled];
}
MacToolBarItemWrapper::MacToolBarItemWrapper(QAction *action, QMacToolBarItem *toolbaritem)
:action(action),toolbaritem(toolbaritem)
{
if(action->isCheckable())
{
connect(action,SIGNAL(toggled(bool)),this,SLOT(actionToggled(bool)));
connect(toolbaritem,SIGNAL(activated()), action, SLOT(toggle()));
updateIcon(action->isChecked());
}
}
void MacToolBarItemWrapper::actionToggled(bool toogled)
{
updateIcon(toogled);
}
void MacToolBarItemWrapper::updateIcon(bool enabled)
{
if(enabled)
{
QIcon icon = action->icon();
QPixmap tempPixmap = icon.pixmap(QSize(24,24));
QPainter painter;
painter.begin(&tempPixmap);
painter.fillRect(QRect(3,22,18,2),QColor("#EBBE00"));
painter.end();
toolbaritem->setIcon(QIcon(tempPixmap));
}
else
toolbaritem->setIcon(action->icon());
}