emainwindow fixes
This commit is contained in:
@@ -7,10 +7,10 @@
|
||||
|
||||
EMainWindow::EMainWindow(QWidget * parent): QMainWindow(parent), action_show_all_tools(this), action_hide_all_tools(this),
|
||||
action_show_all_docks(this), action_hide_all_docks(this), first_show(true) {
|
||||
tid = 0;
|
||||
menu_recent = 0;
|
||||
action_clear_recent = new QAction(QIcon(":/icons/edit-clear.png"), tr("Clear recent list"), this);
|
||||
connect(action_clear_recent, SIGNAL(triggered()), this, SLOT(clearRecent()));
|
||||
connect(this, &QMainWindow::tabifiedDockWidgetActivated, this, [](QDockWidget*w){qDebug() << "tabifiedDockWidgetActivated" << w;});
|
||||
qRegisterMetaType<Qt::DockWidgetArea>("Qt::DockWidgetArea");
|
||||
action_show_all_tools.setText(tr("Show all"));
|
||||
action_show_all_docks.setText(tr("Show all"));
|
||||
@@ -24,13 +24,10 @@ action_show_all_docks(this), action_hide_all_docks(this), first_show(true) {
|
||||
setChanged(false);
|
||||
initMenus();
|
||||
initSession();
|
||||
tid = startTimer(200); // bad timer, too much overload
|
||||
}
|
||||
|
||||
|
||||
EMainWindow::~EMainWindow() {
|
||||
if (tid > 0) killTimer(tid);
|
||||
tid = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +58,10 @@ void EMainWindow::showEvent(QShowEvent * e) {
|
||||
if (!first_show) return;
|
||||
first_show = false;
|
||||
QList<QDockWidget * > docks(findChildren<QDockWidget * >());
|
||||
foreach (QDockWidget * d, docks) {
|
||||
for (QDockWidget * d: docks) {
|
||||
connect(d, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(changedDock()));
|
||||
connect(d, SIGNAL(topLevelChanged(bool)), this, SLOT(changedDock()));
|
||||
connect(d, SIGNAL(visibilityChanged(bool)), this, SLOT(changedDock()));
|
||||
}
|
||||
changedDock();
|
||||
}
|
||||
@@ -76,17 +74,22 @@ void EMainWindow::closeEvent(QCloseEvent * e) {
|
||||
|
||||
|
||||
bool EMainWindow::eventFilter(QObject * o, QEvent * e) {
|
||||
//qDebug() << o << e;
|
||||
if (tbars.contains((QTabBar*)o) && e->type() == QEvent::MouseButtonDblClick) {
|
||||
int tab = ((QTabBar*)o)->tabAt(((QMouseEvent * )e)->pos());
|
||||
if (tab >= 0) {
|
||||
QDockWidget * dock = (QDockWidget * )(((QTabBar*)o)->tabData(tab).toULongLong());
|
||||
if (dock != 0) {
|
||||
if (dock) {
|
||||
dock->setFloating(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e->type() == QEvent::Show || e->type() == QEvent::Hide || e->type() == QEvent::ChildAdded || e->type() == QEvent::ChildRemoved || e->type() == QEvent::MouseButtonPress) {
|
||||
/*if (e->type() == QEvent::Show || e->type() == QEvent::Hide) {
|
||||
if (tdocks.contains((QDockWidget*)o)) {
|
||||
changedDock();
|
||||
}
|
||||
}*/
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (tbars.contains((QTabBar*)o) || tdocks.contains((QDockWidget*)o)) {
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (((QMouseEvent*)e)->button() == Qt::RightButton) {
|
||||
@@ -105,37 +108,24 @@ bool EMainWindow::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e->type() == QEvent::Show || e->type() == QEvent::Hide) {
|
||||
//qDebug() << "filter";
|
||||
changedDock();
|
||||
}
|
||||
}
|
||||
}
|
||||
return QMainWindow::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
void EMainWindow::timerEvent(QTimerEvent * e) {
|
||||
if (e->timerId() == tid) {
|
||||
changedDock();
|
||||
return;
|
||||
}
|
||||
QMainWindow::timerEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void EMainWindow::changeEvent(QEvent * e) {
|
||||
QMainWindow::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
action_show_all_tools.setText(tr("Show all"));
|
||||
action_show_all_docks.setText(tr("Show all"));
|
||||
action_hide_all_tools.setText(tr("Hide all"));
|
||||
action_hide_all_docks.setText(tr("Hide all"));
|
||||
action_clear_recent->setText(tr("Clear recent list"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange:
|
||||
action_show_all_tools.setText(tr("Show all"));
|
||||
action_show_all_docks.setText(tr("Show all"));
|
||||
action_hide_all_tools.setText(tr("Hide all"));
|
||||
action_hide_all_docks.setText(tr("Hide all"));
|
||||
action_clear_recent->setText(tr("Clear recent list"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +149,7 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
lbl->setAlignment(Qt::AlignCenter);
|
||||
wa->setDefaultWidget(lbl);
|
||||
menuPopup->addAction(wa);
|
||||
foreach (QToolBar * i, tools) {
|
||||
for (QToolBar * i: tools) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
a = new QAction(i->windowTitle(), menuPopup);
|
||||
a->setCheckable(true);
|
||||
@@ -184,7 +174,7 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
lbl->setAlignment(Qt::AlignCenter);
|
||||
wa->setDefaultWidget(lbl);
|
||||
menuPopup->addAction(wa);
|
||||
foreach (QDockWidget * i, docks) {
|
||||
for (QDockWidget * i: docks) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
a = new QAction(i->windowTitle(), menuPopup);
|
||||
a->setCheckable(true);
|
||||
@@ -244,7 +234,7 @@ void EMainWindow::initMenus() {
|
||||
action_hide_all_docks.disconnect();
|
||||
|
||||
QList<QToolBar * > tools = findChildren<QToolBar * >();
|
||||
foreach (QToolBar * i, tools) {
|
||||
for (QToolBar * i: tools) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
i->toggleViewAction()->setIcon(i->windowIcon());
|
||||
connect(&action_show_all_tools, SIGNAL(triggered(bool)), i, SLOT(show()));
|
||||
@@ -252,7 +242,7 @@ void EMainWindow::initMenus() {
|
||||
}
|
||||
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
foreach (QDockWidget * i, docks) {
|
||||
for (QDockWidget * i: docks) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
i->toggleViewAction()->setIcon(i->windowIcon());
|
||||
connect(&action_show_all_docks, SIGNAL(triggered(bool)), i, SLOT(show()));
|
||||
@@ -260,7 +250,7 @@ void EMainWindow::initMenus() {
|
||||
}
|
||||
|
||||
QList<QAction * > actions = findChildren<QAction * >();
|
||||
foreach (QAction * i, actions)
|
||||
for (QAction * i: actions)
|
||||
i->setIconVisibleInMenu(true);
|
||||
addActions(actions);
|
||||
}
|
||||
@@ -290,35 +280,41 @@ bool EMainWindow::checkSave() {
|
||||
|
||||
void EMainWindow::changedDock() {
|
||||
if (isHidden()) return;
|
||||
QSet<QDockWidget * > invalid_tab_docks;
|
||||
QList<QTabBar * > tabs(findChildren<QTabBar * >());
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QDockWidget * dock;
|
||||
// qDebug() << "### change";
|
||||
foreach (QTabBar * t, tabs) {
|
||||
QRect geom = geometry();
|
||||
//qDebug() << "### change" << docks.size() << tabs.size();
|
||||
for (QTabBar * t: tabs) {
|
||||
if (!t->objectName().isEmpty() || t->isHidden()) continue;
|
||||
if (!tbars.contains(t)) {
|
||||
//qDebug() << "add tab" << t;
|
||||
tbars << t;
|
||||
connect(t, SIGNAL(tabCloseRequested(int)), this, SLOT(closeDock(int)));
|
||||
connect(t, &QObject::destroyed, this, [this,t](){tbars.removeOne(t);});
|
||||
t->installEventFilter(this);
|
||||
#ifndef Q_OS_MACOS
|
||||
t->setIconSize(dockTabsIconSize());
|
||||
#endif
|
||||
t->setTabsClosable(true);
|
||||
}
|
||||
// qDebug() << "tab" << t << t->count();
|
||||
for (int i = 0; i < t->count(); ++i) {
|
||||
dock = (QDockWidget * )t->tabData(i).toULongLong();
|
||||
//qDebug() << i << t->tabData(i);
|
||||
QDockWidget * dock = (QDockWidget * )t->tabData(i).toULongLong();
|
||||
//qDebug() << i << t->tabText(i) << t->isTabVisible(i) << dock;
|
||||
if (!dock) continue;
|
||||
if (!docks.contains(dock)) continue;
|
||||
if (!geom.intersects(t->geometry()))
|
||||
invalid_tab_docks << dock;
|
||||
#ifndef Q_OS_MACOS
|
||||
t->setIconSize(dockTabsIconSize());
|
||||
QSize is = dockTabsIconSize();
|
||||
if (t->iconSize() != is) t->setIconSize(is);
|
||||
#endif
|
||||
t->setTabIcon(i, dock->windowIcon());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (QDockWidget * d, docks) {
|
||||
if (d->titleBarWidget() == 0) continue;
|
||||
for (QDockWidget * d: docks) {
|
||||
if (!d->titleBarWidget()) continue;
|
||||
QWidget * ctb = d->titleBarWidget();
|
||||
if (!d->property("__titleWidget").isValid()) {
|
||||
d->setProperty("__titleWidget", qulonglong(ctb));
|
||||
@@ -329,10 +325,13 @@ void EMainWindow::changedDock() {
|
||||
d->setProperty("__titleEmptyWidget", qulonglong(ntb));
|
||||
}
|
||||
if (!tdocks.contains(d)) {
|
||||
//qDebug() << "add dock" << d;
|
||||
tdocks << d;
|
||||
connect(d, &QObject::destroyed, this, [this,d](){tdocks.removeOne(d);});
|
||||
d->installEventFilter(this);
|
||||
}
|
||||
if (tabifiedDockWidgets(d).isEmpty()) {
|
||||
//qDebug() << d->windowTitle() << tabifiedDockWidgets(d);
|
||||
if (tabifiedDockWidgets(d).isEmpty() || invalid_tab_docks.contains(d)) {
|
||||
if (d->titleBarWidget() != (QWidget * )(d->property("__titleWidget").toULongLong()))
|
||||
d->setTitleBarWidget((QWidget * )(d->property("__titleWidget").toULongLong()));
|
||||
} else {
|
||||
|
||||
@@ -91,7 +91,6 @@ protected:
|
||||
void showEvent(QShowEvent * );
|
||||
void closeEvent(QCloseEvent * );
|
||||
bool eventFilter(QObject * o, QEvent * e);
|
||||
void timerEvent(QTimerEvent * e);
|
||||
void changeEvent(QEvent * e);
|
||||
QMenu * createPopupMenu();
|
||||
void addToRecent(const QString & path);
|
||||
@@ -121,7 +120,7 @@ protected:
|
||||
QMenu * menu_recent;
|
||||
SessionManager session;
|
||||
bool isChanged, first_show;
|
||||
int tid, max_recent;
|
||||
int max_recent;
|
||||
|
||||
private slots:
|
||||
void changedDock();
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
class __QADTranslators__ {
|
||||
public:
|
||||
static QList<QTranslator * > translators;
|
||||
static QList<QTranslator * > & translators() {
|
||||
static QList<QTranslator * > ret;
|
||||
return ret;
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
QList<QTranslator * > __QADTranslators__::translators = QList<QTranslator * >();
|
||||
|
||||
|
||||
QString QAD::userPath(QAD::LocationType loc, QString name) {
|
||||
QString dir, ext;
|
||||
@@ -68,16 +69,12 @@ QStringList QAD::resourcePaths(QString type) {
|
||||
|
||||
|
||||
void QAD::loadTranslations(QString lang) {
|
||||
foreach (QTranslator * t, __QADTranslators__::translators) {
|
||||
qApp->removeTranslator(t);
|
||||
delete t;
|
||||
}
|
||||
__QADTranslators__::translators.clear();
|
||||
unloadTranslations();
|
||||
if (lang.isEmpty())
|
||||
lang = QLocale().bcp47Name();
|
||||
QString short_lang = lang.left(2);
|
||||
QStringList dirs = resourcePaths("lang");
|
||||
foreach (const QString & d, dirs) {
|
||||
for (const QString & d: dirs) {
|
||||
QDirIterator dit(d);
|
||||
while (dit.hasNext()) {
|
||||
dit.next();
|
||||
@@ -87,7 +84,7 @@ void QAD::loadTranslations(QString lang) {
|
||||
QTranslator * tr = new QTranslator();
|
||||
if (tr->load(dit.filePath())) {
|
||||
qApp->installTranslator(tr);
|
||||
__QADTranslators__::translators << tr;
|
||||
__QADTranslators__::translators() << tr;
|
||||
//qDebug() << "Add tr" << dit.fileName();
|
||||
} else {
|
||||
qDebug() << "Can`t load translation" << dit.fileName();
|
||||
@@ -98,10 +95,22 @@ void QAD::loadTranslations(QString lang) {
|
||||
}
|
||||
|
||||
|
||||
void QAD::unloadTranslations() {
|
||||
//qDebug() << "removeTranslator ...";
|
||||
for (QTranslator * t: __QADTranslators__::translators()) {
|
||||
qApp->removeTranslator(t);
|
||||
delete t;
|
||||
}
|
||||
__QADTranslators__::translators().clear();
|
||||
//qDebug() << "removeTranslator done";
|
||||
|
||||
}
|
||||
|
||||
|
||||
QStringList QAD::availableTranslations() {
|
||||
QSet<QString> ret;
|
||||
QStringList dirs = resourcePaths("lang");
|
||||
foreach (const QString & d, dirs) {
|
||||
for (const QString & d: dirs) {
|
||||
QDirIterator dit(d);
|
||||
while (dit.hasNext()) {
|
||||
dit.next();
|
||||
@@ -129,4 +138,3 @@ QStringList QAD::availableTranslations() {
|
||||
}
|
||||
return ret.values();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace QAD {
|
||||
|
||||
|
||||
QAD_UTILS_EXPORT void loadTranslations(QString lang = QString());
|
||||
QAD_UTILS_EXPORT void unloadTranslations();
|
||||
|
||||
|
||||
QAD_UTILS_EXPORT QStringList availableTranslations();
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "qad_types.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "pitime.h"
|
||||
#include <QDebug>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
@@ -9,4 +11,42 @@ int main(int argc, char *argv[]) {
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
|
||||
/*PITimeMeasurer tm;
|
||||
int cnt = 1000000;
|
||||
int el_o = 0, el_n = 0, el_q = 0;
|
||||
double v = 0.;
|
||||
NO_UNUSED(v);
|
||||
|
||||
PIStringList nums({"", "1", "123456789", "12.3456789", ".01E+12", "-12345.6789E+123", "-E+100", "-", "-0", "-.", "-0."});
|
||||
for (PIString s: nums) {
|
||||
piCout << "\nstring \"" << s << "\"";
|
||||
const char * data = s.dataAscii();
|
||||
QString qs(data);
|
||||
|
||||
tm.reset();
|
||||
piForTimes (cnt) {
|
||||
v = atof(data);
|
||||
}
|
||||
el_o = tm.elapsed_u();
|
||||
piCout << v << "," << el_o << "us";
|
||||
|
||||
tm.reset();
|
||||
piForTimes (cnt) {
|
||||
v = s.toDouble();
|
||||
}
|
||||
el_n = tm.elapsed_u();
|
||||
piCout << v << "," << el_n << "us";
|
||||
|
||||
tm.reset();
|
||||
piForTimes (cnt) {
|
||||
v = qs.toDouble();
|
||||
}
|
||||
el_q = tm.elapsed_u();
|
||||
qDebug() << v << "," << el_q << "us";
|
||||
|
||||
piCout << "atof/PIP =" << (double)el_o / el_n;
|
||||
piCout << " Qt/PIP =" << (double)el_q / el_n;
|
||||
}
|
||||
return 0;*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user