code format
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "etabwidget.h"
|
||||
|
||||
|
||||
ETabWidget::ETabWidget(QWidget* parent): QTabWidget(parent) {
|
||||
ETabWidget::ETabWidget(QWidget * parent): QTabWidget(parent) {
|
||||
tabBar()->setMouseTracking(true);
|
||||
tabBar()->installEventFilter(this);
|
||||
}
|
||||
@@ -9,26 +9,27 @@ ETabWidget::ETabWidget(QWidget* parent): QTabWidget(parent) {
|
||||
|
||||
void ETabWidget::retranslate() {
|
||||
for (int i = 0; i < buttons.size(); ++i)
|
||||
buttons[i].toolTip = QApplication::translate("MainWindow", buttons[i].srcToolTip.toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/);
|
||||
QList<QToolButton * > bl = findChildren<QToolButton * >();
|
||||
foreach (QToolButton * i, bl)
|
||||
i->setToolTip(QApplication::translate("MainWindow", i->property("sourceToolTip").toString().toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/));
|
||||
buttons[i].toolTip = QApplication::translate("MainWindow", buttons[i].srcToolTip.toUtf8(), 0 /*, QCoreApplication::UnicodeUTF8*/);
|
||||
QList<QToolButton *> bl = findChildren<QToolButton *>();
|
||||
foreach(QToolButton * i, bl)
|
||||
i->setToolTip(
|
||||
QApplication::translate("MainWindow", i->property("sourceToolTip").toString().toUtf8(), 0 /*, QCoreApplication::UnicodeUTF8*/));
|
||||
}
|
||||
|
||||
|
||||
int ETabWidget::addTab(QWidget * page, const QIcon & icon, const QString & label) {
|
||||
int ret = QTabWidget::addTab(page, icon, label);
|
||||
int ret = QTabWidget::addTab(page, icon, label);
|
||||
QWidget * w = new QWidget();
|
||||
w->setLayout(new QBoxLayout(QBoxLayout::RightToLeft));
|
||||
w->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
w->layout()->setSpacing(2);
|
||||
QToolButton * b;
|
||||
foreach (const TabButton & i, buttons) {
|
||||
foreach(const TabButton & i, buttons) {
|
||||
b = new QToolButton();
|
||||
b->setToolTip(i.toolTip);
|
||||
b->setIconSize(QSize(16, 16));
|
||||
b->setIcon(i.icon);
|
||||
//b->setFlat(true);
|
||||
// b->setFlat(true);
|
||||
b->setProperty("sourceToolTip", i.toolTip);
|
||||
b->setProperty("buttonRole", i.role);
|
||||
connect(b, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
|
||||
@@ -41,14 +42,12 @@ int ETabWidget::addTab(QWidget * page, const QIcon & icon, const QString & label
|
||||
|
||||
|
||||
void ETabWidget::setButtonVisible(int role, bool yes) {
|
||||
QList<QToolButton * > bl = findChildren<QToolButton * >();
|
||||
foreach (QToolButton * i, bl)
|
||||
if (i->property("buttonRole").toInt() == role)
|
||||
i->setVisible(yes);
|
||||
QList<QToolButton *> bl = findChildren<QToolButton *>();
|
||||
foreach(QToolButton * i, bl)
|
||||
if (i->property("buttonRole").toInt() == role) i->setVisible(yes);
|
||||
QWidget * w;
|
||||
for (int i = 0; i < buttons.size(); ++i) {
|
||||
if (buttons[i].role == role)
|
||||
buttons[i].visible = yes;
|
||||
if (buttons[i].role == role) buttons[i].visible = yes;
|
||||
w = tabBar()->tabButton(i, QTabBar::RightSide);
|
||||
if (w != 0) w->adjustSize();
|
||||
}
|
||||
@@ -57,19 +56,19 @@ void ETabWidget::setButtonVisible(int role, bool yes) {
|
||||
|
||||
/*
|
||||
void ETabWidget::removeTab(int index) {
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(1)->widget()));
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(0)->widget()));
|
||||
QTabWidget::removeTab(index);
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(1)->widget()));
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(0)->widget()));
|
||||
QTabWidget::removeTab(index);
|
||||
}
|
||||
*/
|
||||
|
||||
bool ETabWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
static int prev = -1;
|
||||
if (e->type() == QEvent::MouseMove) {
|
||||
QTabBar * t = qobject_cast<QTabBar * >(o);
|
||||
QTabBar * t = qobject_cast<QTabBar *>(o);
|
||||
if (t == 0) return QTabWidget::eventFilter(o, e);
|
||||
for (int i = 0; i < count(); ++i)
|
||||
if (t->tabRect(i).contains(((QMouseEvent * )e)->pos())) {
|
||||
if (t->tabRect(i).contains(((QMouseEvent *)e)->pos())) {
|
||||
if (i != prev) {
|
||||
prev = i;
|
||||
emit tabHovered(i);
|
||||
@@ -94,17 +93,14 @@ bool ETabWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
void ETabWidget::changeEvent(QEvent * e) {
|
||||
QTabWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: retranslate(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ETabWidget::buttonClicked() {
|
||||
QToolButton * s = qobject_cast<QToolButton * >(sender());
|
||||
QToolButton * s = qobject_cast<QToolButton *>(sender());
|
||||
if (s == 0) return;
|
||||
QWidget * pw = s->parentWidget();
|
||||
if (pw == 0) return;
|
||||
|
||||
Reference in New Issue
Block a user