code format
This commit is contained in:
@@ -1,49 +1,45 @@
|
||||
#include "ribbon.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
Ribbon::Ribbon(QMainWindow * parent_): QToolBar() {
|
||||
tab = 0;
|
||||
tab = 0;
|
||||
scroll_area = 0;
|
||||
delay_e = true;
|
||||
delay = 1000;
|
||||
hovered = -1;
|
||||
delay_e = true;
|
||||
delay = 1000;
|
||||
hovered = -1;
|
||||
setObjectName("ribbon");
|
||||
setProperty("ribbon", true);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
parent = parent_;
|
||||
if (parent_)
|
||||
parent_->installEventFilter(this);
|
||||
if (parent_) parent_->installEventFilter(this);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
Ribbon::~Ribbon() {
|
||||
}
|
||||
Ribbon::~Ribbon() {}
|
||||
|
||||
|
||||
bool Ribbon::eventFilter(QObject * o, QEvent * e) {
|
||||
//qDebug() << e;
|
||||
// qDebug() << e;
|
||||
if (o == parent) {
|
||||
if (e->type() == QEvent::Resize || e->type() == QEvent::WindowActivate)
|
||||
_resize();
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish)
|
||||
_setIconsSize();
|
||||
if (e->type() == QEvent::Resize || e->type() == QEvent::WindowActivate) _resize();
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) _setIconsSize();
|
||||
return QToolBar::eventFilter(o, e);
|
||||
}
|
||||
if (e->type() == QEvent::ActionChanged) {
|
||||
QToolButton * b = qobject_cast<QToolButton * >((QObject * )o->property("ribbonButton").toLongLong());
|
||||
if (b != 0)
|
||||
b->setEnabled(qobject_cast<QAction * >(o)->isEnabled());
|
||||
QToolButton * b = qobject_cast<QToolButton *>((QObject *)o->property("ribbonButton").toLongLong());
|
||||
if (b != 0) b->setEnabled(qobject_cast<QAction *>(o)->isEnabled());
|
||||
}
|
||||
return QToolBar::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
void Ribbon::timerEvent(QTimerEvent * e) {
|
||||
if (hovers.value(e->timerId(), -1) == hovered)
|
||||
tab->setCurrentIndex(hovered);
|
||||
if (hovers.value(e->timerId(), -1) == hovered) tab->setCurrentIndex(hovered);
|
||||
hovers.remove(e->timerId());
|
||||
killTimer(e->timerId());
|
||||
}
|
||||
@@ -52,11 +48,8 @@ void Ribbon::timerEvent(QTimerEvent * e) {
|
||||
void Ribbon::changeEvent(QEvent * e) {
|
||||
QToolBar::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: retranslate(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,16 +57,16 @@ void Ribbon::changeEvent(QEvent * e) {
|
||||
void Ribbon::_resize() {
|
||||
return; // WARNING
|
||||
for (int i = 0; i < tab->count(); ++i) {
|
||||
int h = ((QScrollArea*)(tab->widget(i)))->sizeHint().height();
|
||||
if (((QScrollArea*)(tab->widget(i)))->horizontalScrollBar()->isVisible())
|
||||
h += ((QScrollArea*)(tab->widget(i)))->horizontalScrollBar()->height();
|
||||
((QScrollArea*)(tab->widget(i)))->setMinimumHeight(h);
|
||||
int h = ((QScrollArea *)(tab->widget(i)))->sizeHint().height();
|
||||
if (((QScrollArea *)(tab->widget(i)))->horizontalScrollBar()->isVisible())
|
||||
h += ((QScrollArea *)(tab->widget(i)))->horizontalScrollBar()->height();
|
||||
((QScrollArea *)(tab->widget(i)))->setMinimumHeight(h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Ribbon::_setIconsSize() {
|
||||
//qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
// qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
setTabIconSize(preferredIconSize(2, this));
|
||||
setIconSize(preferredIconSize(3, this));
|
||||
}
|
||||
@@ -86,7 +79,6 @@ void Ribbon::_setButtonText(QToolButton * b, QAction * a) {
|
||||
sc += "\n" + s.toString(QKeySequence::NativeText);
|
||||
}
|
||||
b->setToolTip(a->text() + sc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -101,11 +93,10 @@ void Ribbon::setVisible(bool yes) {
|
||||
void Ribbon::init() {
|
||||
if (parent == 0) return;
|
||||
if (parent->menuBar() == 0) return;
|
||||
QList<QAction * > lm = parent->menuBar()->actions(), la;
|
||||
QList<QAction *> lm = parent->menuBar()->actions(), la;
|
||||
QString prev_tab;
|
||||
if (tab) {
|
||||
if (tab->currentIndex() >= 0)
|
||||
prev_tab = tab->tabText(tab->currentIndex());
|
||||
if (tab->currentIndex() >= 0) prev_tab = tab->tabText(tab->currentIndex());
|
||||
tab->deleteLater();
|
||||
}
|
||||
clear();
|
||||
@@ -117,24 +108,24 @@ void Ribbon::init() {
|
||||
connect(tab, SIGNAL(currentChanged(int)), this, SIGNAL(currentTabChanged(int)));
|
||||
tab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
QFrame * g;
|
||||
QBoxLayout * l, * tl;
|
||||
QBoxLayout *l, *tl;
|
||||
QToolButton * b;
|
||||
//tab->setIconSize(QSize(32, 32));
|
||||
// tab->setIconSize(QSize(32, 32));
|
||||
for (QAction * i: lm) {
|
||||
if (!i->menu()) continue;
|
||||
//if (!i->menu()->isVisible()) continue;
|
||||
la = i->menu()->actions();
|
||||
// if (!i->menu()->isVisible()) continue;
|
||||
la = i->menu()->actions();
|
||||
QIcon tic = i->icon();
|
||||
if (!tic.isNull())
|
||||
i->setProperty("__icon", QVariant::fromValue<QIcon>(tic));
|
||||
else
|
||||
tic = i->property("__icon").value<QIcon>();
|
||||
//#ifdef Q_OS_MACOS
|
||||
// tic = QIcon();
|
||||
//#endif
|
||||
// #ifdef Q_OS_MACOS
|
||||
// tic = QIcon();
|
||||
// #endif
|
||||
tab->addTab(new QWidget(), tic, i->text());
|
||||
//qDebug() << this << i->icon() << i->text();
|
||||
//continue;
|
||||
// qDebug() << this << i->icon() << i->text();
|
||||
// continue;
|
||||
/*QScrollArea * sa = new QScrollArea();
|
||||
sa->setWidget(new QWidget());
|
||||
sa->setWidgetResizable(true);
|
||||
@@ -143,7 +134,7 @@ void Ribbon::init() {
|
||||
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
sa->setFrameShape(QFrame::NoFrame);
|
||||
tab->addTab(sa, i->icon(), i->text());*/
|
||||
tab->widget(tab->count() - 1)->setProperty("ribbonAction", qlonglong((void * )i));
|
||||
tab->widget(tab->count() - 1)->setProperty("ribbonAction", qlonglong((void *)i));
|
||||
i->setIcon(QIcon());
|
||||
tl = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
tl->setSpacing(2);
|
||||
@@ -152,7 +143,8 @@ void Ribbon::init() {
|
||||
#else
|
||||
tl->setContentsMargins(2, 0, 2, 2);
|
||||
#endif
|
||||
g = new QFrame(); g->setFrameShape(QFrame::StyledPanel);
|
||||
g = new QFrame();
|
||||
g->setFrameShape(QFrame::StyledPanel);
|
||||
l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
g->setLayout(l);
|
||||
l->setSpacing(2);
|
||||
@@ -161,24 +153,25 @@ void Ribbon::init() {
|
||||
if (j->isSeparator()) {
|
||||
if (l->isEmpty()) continue;
|
||||
tl->addWidget(g);
|
||||
g = new QFrame(); g->setFrameShape(QFrame::StyledPanel);
|
||||
g = new QFrame();
|
||||
g->setFrameShape(QFrame::StyledPanel);
|
||||
l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
l->setSpacing(2);
|
||||
l->setContentsMargins(2, 2, 2, 2);
|
||||
g->setLayout(l);
|
||||
continue;
|
||||
}
|
||||
if (qobject_cast<QWidgetAction*>(j)) {
|
||||
QWidget * _w = qobject_cast<QWidgetAction*>(j)->defaultWidget();
|
||||
if (qobject_cast<QWidgetAction *>(j)) {
|
||||
QWidget * _w = qobject_cast<QWidgetAction *>(j)->defaultWidget();
|
||||
l->addWidget(_w);
|
||||
_w->show();
|
||||
continue;
|
||||
}
|
||||
b = new QToolButton();
|
||||
//b->setVisible(j->isVisible());
|
||||
// b->setVisible(j->isVisible());
|
||||
b->setEnabled(j->isEnabled());
|
||||
b->setProperty("ribbonAction", qlonglong((void * )j));
|
||||
j->setProperty("ribbonButton", qlonglong((void * )b));
|
||||
b->setProperty("ribbonAction", qlonglong((void *)j));
|
||||
j->setProperty("ribbonButton", qlonglong((void *)b));
|
||||
j->installEventFilter(this);
|
||||
if (j->menu() != 0) {
|
||||
b->setPopupMode(QToolButton::InstantPopup);
|
||||
@@ -193,11 +186,11 @@ void Ribbon::init() {
|
||||
} else
|
||||
connect(b, SIGNAL(clicked()), j, SLOT(trigger()));
|
||||
}
|
||||
//b->setIconSize(QSize(16, 16));
|
||||
// b->setIconSize(QSize(16, 16));
|
||||
b->setIcon(j->icon());
|
||||
_setButtonText(b, j);
|
||||
//b->addAction(j);
|
||||
//b->setShortcut(j->shortcut());
|
||||
// b->addAction(j);
|
||||
// b->setShortcut(j->shortcut());
|
||||
b->setAutoRaise(true);
|
||||
b->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
@@ -206,10 +199,9 @@ void Ribbon::init() {
|
||||
}
|
||||
tl->addWidget(g);
|
||||
tl->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed));
|
||||
//sa->widget()->setLayout(tl);
|
||||
// sa->widget()->setLayout(tl);
|
||||
tab->widget(tab->count() - 1)->setLayout(tl);
|
||||
if (i->text() == prev_tab)
|
||||
tab->setCurrentIndex(tab->count() - 1);
|
||||
if (i->text() == prev_tab) tab->setCurrentIndex(tab->count() - 1);
|
||||
}
|
||||
setFloatable(false);
|
||||
setMovable(false);
|
||||
@@ -219,7 +211,7 @@ void Ribbon::init() {
|
||||
scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scroll_area->setWidget(tab);*/
|
||||
_resize();
|
||||
//addWidget(scroll_area);
|
||||
// addWidget(scroll_area);
|
||||
addWidget(tab);
|
||||
parent->addToolBar(Qt::TopToolBarArea, this);
|
||||
parent->menuBar()->hide();
|
||||
@@ -231,13 +223,13 @@ void Ribbon::init() {
|
||||
void Ribbon::retranslate() {
|
||||
QAction * a;
|
||||
for (QToolButton * i: buttons) {
|
||||
a = (QAction * )(i->property("ribbonAction").toLongLong());
|
||||
a = (QAction *)(i->property("ribbonAction").toLongLong());
|
||||
if (a == 0) continue;
|
||||
_setButtonText(i, a);
|
||||
//i->setShortcut(a->shortcut());
|
||||
// i->setShortcut(a->shortcut());
|
||||
}
|
||||
for (int i = 0; i < tab->count(); ++i) {
|
||||
a = (QAction * )(tab->widget(i)->property("ribbonAction").toLongLong());
|
||||
a = (QAction *)(tab->widget(i)->property("ribbonAction").toLongLong());
|
||||
if (a == 0) continue;
|
||||
tab->setTabText(i, a->text());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user