code format
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
#include "emainwindow.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
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) {
|
||||
menu_recent = 0;
|
||||
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) {
|
||||
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()));
|
||||
qRegisterMetaType<Qt::DockWidgetArea>("Qt::DockWidgetArea");
|
||||
@@ -26,8 +32,7 @@ action_show_all_docks(this), action_hide_all_docks(this), first_show(true) {
|
||||
}
|
||||
|
||||
|
||||
EMainWindow::~EMainWindow() {
|
||||
}
|
||||
EMainWindow::~EMainWindow() {}
|
||||
|
||||
|
||||
void EMainWindow::setRecentFiles(const QStringList & rl) {
|
||||
@@ -39,7 +44,7 @@ void EMainWindow::setRecentFiles(const QStringList & rl) {
|
||||
|
||||
QStringList EMainWindow::recentFiles() const {
|
||||
QStringList ret;
|
||||
foreach (QAction * a, actions_recent)
|
||||
foreach(QAction * a, actions_recent)
|
||||
ret << a->data().toString();
|
||||
return ret;
|
||||
}
|
||||
@@ -56,7 +61,7 @@ void EMainWindow::showEvent(QShowEvent * e) {
|
||||
initMenus();
|
||||
if (!first_show) return;
|
||||
first_show = false;
|
||||
QList<QDockWidget * > docks(findChildren<QDockWidget * >());
|
||||
QList<QDockWidget *> docks(findChildren<QDockWidget *>());
|
||||
for (QDockWidget * d: docks) {
|
||||
connect(d, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(changedDock()));
|
||||
connect(d, SIGNAL(topLevelChanged(bool)), this, SLOT(changedDock()));
|
||||
@@ -67,16 +72,18 @@ void EMainWindow::showEvent(QShowEvent * e) {
|
||||
|
||||
|
||||
void EMainWindow::closeEvent(QCloseEvent * e) {
|
||||
if (!checkSave()) e->ignore();
|
||||
else saveSession();
|
||||
if (!checkSave())
|
||||
e->ignore();
|
||||
else
|
||||
saveSession();
|
||||
}
|
||||
|
||||
|
||||
bool EMainWindow::eventFilter(QObject * o, QEvent * e) {
|
||||
if (tbars.contains((QTabBar*)o) && e->type() == QEvent::MouseButtonDblClick) {
|
||||
int tab = ((QTabBar*)o)->tabAt(((QMouseEvent * )e)->pos());
|
||||
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());
|
||||
QDockWidget * dock = (QDockWidget *)(((QTabBar *)o)->tabData(tab).toULongLong());
|
||||
if (dock) {
|
||||
dock->setFloating(true);
|
||||
return true;
|
||||
@@ -84,25 +91,25 @@ bool EMainWindow::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
}
|
||||
/*if (e->type() == QEvent::Show || e->type() == QEvent::Hide) {
|
||||
if (tdocks.contains((QDockWidget*)o)) {
|
||||
changedDock();
|
||||
}
|
||||
if (tdocks.contains((QDockWidget*)o)) {
|
||||
changedDock();
|
||||
}
|
||||
}*/
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (tbars.contains((QTabBar*)o) || tdocks.contains((QDockWidget*)o)) {
|
||||
if (tbars.contains((QTabBar *)o) || tdocks.contains((QDockWidget *)o)) {
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (((QMouseEvent*)e)->button() == Qt::RightButton) {
|
||||
bool popup = tbars.contains((QTabBar*)o);
|
||||
if (tdocks.contains((QDockWidget*)o))
|
||||
popup = popup || ((QDockWidget*)o)->titleBarWidget()->geometry().contains(((QMouseEvent*)e)->pos());
|
||||
if (((QMouseEvent *)e)->button() == Qt::RightButton) {
|
||||
bool popup = tbars.contains((QTabBar *)o);
|
||||
if (tdocks.contains((QDockWidget *)o))
|
||||
popup = popup || ((QDockWidget *)o)->titleBarWidget()->geometry().contains(((QMouseEvent *)e)->pos());
|
||||
if (popup) {
|
||||
createPopupMenu()->popup(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QMouseEvent*)e)->globalPos()
|
||||
((QMouseEvent *)e)->globalPos()
|
||||
#else
|
||||
((QMouseEvent*)e)->globalPosition().toPoint()
|
||||
((QMouseEvent *)e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -123,8 +130,7 @@ void EMainWindow::changeEvent(QEvent * e) {
|
||||
action_hide_all_docks.setText(tr("Hide all"));
|
||||
action_clear_recent->setText(tr("Clear recent list"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +143,9 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
// Toolbars
|
||||
QList<QToolBar * > tools = findChildren<QToolBar * >();
|
||||
QList<QToolBar *> tools = findChildren<QToolBar *>();
|
||||
if (!tools.isEmpty()) {
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
lbl = new QLabel();
|
||||
lbl->setFrameShape(QFrame::StyledPanel);
|
||||
lbl->setFrameShadow(QFrame::Sunken);
|
||||
@@ -162,9 +168,9 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
menuPopup->addAction(&action_hide_all_tools);
|
||||
}
|
||||
// Docks
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
if (!docks.isEmpty()) {
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
lbl = new QLabel();
|
||||
lbl->setFrameShape(QFrame::StyledPanel);
|
||||
lbl->setFrameShadow(QFrame::Sunken);
|
||||
@@ -193,7 +199,7 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
void EMainWindow::addToRecent(const QString & path) {
|
||||
if (path.isEmpty()) return;
|
||||
QFileInfo fi(path);
|
||||
QString fp = fi.absoluteFilePath();
|
||||
QString fp = fi.absoluteFilePath();
|
||||
bool insert = true;
|
||||
for (int i = 0; i < actions_recent.size(); ++i)
|
||||
if (actions_recent[i]->data().toString() == fp) {
|
||||
@@ -232,7 +238,7 @@ void EMainWindow::initMenus() {
|
||||
action_show_all_docks.disconnect();
|
||||
action_hide_all_docks.disconnect();
|
||||
|
||||
QList<QToolBar * > tools = findChildren<QToolBar * >();
|
||||
QList<QToolBar *> tools = findChildren<QToolBar *>();
|
||||
for (QToolBar * i: tools) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
i->toggleViewAction()->setIcon(i->windowIcon());
|
||||
@@ -240,7 +246,7 @@ void EMainWindow::initMenus() {
|
||||
connect(&action_hide_all_tools, SIGNAL(triggered(bool)), i, SLOT(hide()));
|
||||
}
|
||||
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
for (QDockWidget * i: docks) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
i->toggleViewAction()->setIcon(i->windowIcon());
|
||||
@@ -248,7 +254,7 @@ void EMainWindow::initMenus() {
|
||||
connect(&action_hide_all_docks, SIGNAL(triggered(bool)), i, SLOT(hide()));
|
||||
}
|
||||
|
||||
QList<QAction * > actions = findChildren<QAction * >();
|
||||
QList<QAction *> actions = findChildren<QAction *>();
|
||||
for (QAction * i: actions)
|
||||
i->setIconVisibleInMenu(true);
|
||||
addActions(actions);
|
||||
@@ -256,8 +262,8 @@ void EMainWindow::initMenus() {
|
||||
|
||||
|
||||
void EMainWindow::initSession() {
|
||||
connect(&session, SIGNAL(loading(QPIConfig & )), this, SLOT(sessionLoading(QPIConfig & )));
|
||||
connect(&session, SIGNAL(saving(QPIConfig & )), this, SLOT(sessionSaving(QPIConfig & )));
|
||||
connect(&session, SIGNAL(loading(QPIConfig &)), this, SLOT(sessionLoading(QPIConfig &)));
|
||||
connect(&session, SIGNAL(saving(QPIConfig &)), this, SLOT(sessionSaving(QPIConfig &)));
|
||||
}
|
||||
|
||||
|
||||
@@ -279,18 +285,18 @@ bool EMainWindow::checkSave() {
|
||||
|
||||
void EMainWindow::changedDock() {
|
||||
if (isHidden()) return;
|
||||
QSet<QDockWidget * > invalid_tab_docks;
|
||||
QList<QTabBar * > tabs(findChildren<QTabBar * >());
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QRect geom = geometry();
|
||||
//qDebug() << "### change" << docks.size() << tabs.size();
|
||||
QSet<QDockWidget *> invalid_tab_docks;
|
||||
QList<QTabBar *> tabs(findChildren<QTabBar *>());
|
||||
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
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;
|
||||
// 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);});
|
||||
connect(t, &QObject::destroyed, this, [this, t]() { tbars.removeOne(t); });
|
||||
t->installEventFilter(this);
|
||||
#ifndef Q_OS_MACOS
|
||||
t->setIconSize(dockTabsIconSize());
|
||||
@@ -298,12 +304,11 @@ void EMainWindow::changedDock() {
|
||||
t->setTabsClosable(true);
|
||||
}
|
||||
for (int i = 0; i < t->count(); ++i) {
|
||||
QDockWidget * dock = (QDockWidget * )t->tabData(i).toULongLong();
|
||||
//qDebug() << i << t->tabText(i) << t->isTabVisible(i) << dock;
|
||||
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;
|
||||
if (!geom.intersects(t->geometry())) invalid_tab_docks << dock;
|
||||
#ifndef Q_OS_MACOS
|
||||
QSize is = dockTabsIconSize();
|
||||
if (t->iconSize() != is) t->setIconSize(is);
|
||||
@@ -318,24 +323,24 @@ void EMainWindow::changedDock() {
|
||||
if (!d->property("__titleWidget").isValid()) {
|
||||
d->setProperty("__titleWidget", qulonglong(ctb));
|
||||
QWidget * ntb = new QWidget();
|
||||
int m = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin);
|
||||
int m = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin);
|
||||
ntb->setLayout(new QBoxLayout(QBoxLayout::BottomToTop));
|
||||
ntb->layout()->setContentsMargins(m, m, 0, 0);
|
||||
d->setProperty("__titleEmptyWidget", qulonglong(ntb));
|
||||
}
|
||||
if (!tdocks.contains(d)) {
|
||||
//qDebug() << "add dock" << d;
|
||||
// qDebug() << "add dock" << d;
|
||||
tdocks << d;
|
||||
connect(d, &QObject::destroyed, this, [this,d](){tdocks.removeOne(d);});
|
||||
connect(d, &QObject::destroyed, this, [this, d]() { tdocks.removeOne(d); });
|
||||
d->installEventFilter(this);
|
||||
}
|
||||
//qDebug() << d->windowTitle() << tabifiedDockWidgets(d);
|
||||
// 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()));
|
||||
if (d->titleBarWidget() != (QWidget *)(d->property("__titleWidget").toULongLong()))
|
||||
d->setTitleBarWidget((QWidget *)(d->property("__titleWidget").toULongLong()));
|
||||
} else {
|
||||
if (d->titleBarWidget() != (QWidget * )(d->property("__titleEmptyWidget").toULongLong())) {
|
||||
d->setTitleBarWidget((QWidget * )(d->property("__titleEmptyWidget").toULongLong()));
|
||||
if (d->titleBarWidget() != (QWidget *)(d->property("__titleEmptyWidget").toULongLong())) {
|
||||
d->setTitleBarWidget((QWidget *)(d->property("__titleEmptyWidget").toULongLong()));
|
||||
d->layout()->setContentsMargins(0, 20, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -344,20 +349,19 @@ void EMainWindow::changedDock() {
|
||||
|
||||
|
||||
void EMainWindow::closeDock(int index) {
|
||||
QDockWidget * dock = (QDockWidget * )((QTabBar*)sender())->tabData(index).toULongLong();
|
||||
QDockWidget * dock = (QDockWidget *)((QTabBar *)sender())->tabData(index).toULongLong();
|
||||
if (dock == 0) return;
|
||||
dock->close();
|
||||
}
|
||||
|
||||
|
||||
void EMainWindow::recentTriggered() {
|
||||
QAction * a = qobject_cast<QAction * >(sender());
|
||||
QAction * a = qobject_cast<QAction *>(sender());
|
||||
if (!a) return;
|
||||
QString path = a->data().toString();
|
||||
if (path.isEmpty()) return;
|
||||
if (!checkSave()) return;
|
||||
if (load(path))
|
||||
addToRecent(path);
|
||||
if (load(path)) addToRecent(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -379,31 +383,32 @@ void EMainWindow::openFile() {
|
||||
if (!checkSave()) return;
|
||||
QString ret = QFileDialog::getOpenFileName(this, tr("Select file to open"), file_name, loadFilter());
|
||||
if (ret.isEmpty()) return;
|
||||
if (load(ret))
|
||||
addToRecent(ret);
|
||||
if (load(ret)) addToRecent(ret);
|
||||
}
|
||||
|
||||
|
||||
void EMainWindow::openFiles() {
|
||||
if (!checkSave()) return;
|
||||
QStringList ret = QFileDialog::getOpenFileNames(this, tr("Select files to open"), file_name, loadFilter());
|
||||
foreach (QString s, ret) {
|
||||
if (load(s))
|
||||
addToRecent(s);
|
||||
foreach(QString s, ret) {
|
||||
if (load(s)) addToRecent(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EMainWindow::saveFile(bool ask) {
|
||||
if (ask) {
|
||||
int ret = QMessageBox::question(this, windowTitle(), tr("Save changes%1?").arg(!file_name.isEmpty() ? (tr(" in") + " \"" + file_name + "\"") : ""), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
|
||||
int ret = QMessageBox::question(this,
|
||||
windowTitle(),
|
||||
tr("Save changes%1?").arg(!file_name.isEmpty() ? (tr(" in") + " \"" + file_name + "\"") : ""),
|
||||
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
|
||||
QMessageBox::Save);
|
||||
if (ret == QMessageBox::Cancel) return false;
|
||||
if (ret == QMessageBox::Save) return saveFile();
|
||||
return true;
|
||||
}
|
||||
if (file_name.isEmpty()) return saveAsFile();
|
||||
if (save(file_name))
|
||||
addToRecent(file_name);
|
||||
if (save(file_name)) addToRecent(file_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -411,8 +416,7 @@ bool EMainWindow::saveFile(bool ask) {
|
||||
bool EMainWindow::saveAsFile() {
|
||||
QString ret = QFileDialog::getSaveFileName(this, tr("Select file to save"), file_name, saveFilter());
|
||||
if (ret.isEmpty()) return false;
|
||||
if (save(ret))
|
||||
addToRecent(ret);
|
||||
if (save(ret)) addToRecent(ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user