14 #include <QDockWidget> 21 #include <QDataStream> 30 QMainWindow(parent), mObjectName(objectName), mWindowTitle(windowTitle)
32 this->setObjectName(mObjectName);
33 this->setWindowTitle(mWindowTitle);
41 QMainWindow(parent), mObjectName(objectName), mWindowTitle(windowTitle)
43 this->setObjectName(mObjectName);
44 this->setWindowTitle(mWindowTitle);
45 mOptions =
profile()->getXmlSettings().descend(this->objectName());
51 void ConsoleWidgetCollection::setupUI()
53 this->setFocusPolicy(Qt::StrongFocus);
55 this->setDockNestingEnabled(
true);
56 this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
58 int consoleCount = this->option(
"consoleCount").
readVariant(-1).toInt();
60 for (
int i=0; i<consoleCount; ++i)
68 this->restoreState(this->option(
"windowState").readVariant().toByteArray());
71 if (mDockWidgets.empty())
85 this->option(
"windowState").
writeVariant(this->saveState());
86 this->option(
"consoleCount").
writeVariant(QVariant::fromValue<int>(mDockWidgets.size()));
89 void ConsoleWidgetCollection::onDockWidgetVisibilityChanged(
bool val)
91 if (!this->isVisible())
97 QTimer::singleShot(0,
this, SLOT(checkVisibility()));
100 void ConsoleWidgetCollection::checkVisibility()
102 this->removeHiddenConsoles();
105 void ConsoleWidgetCollection::removeHiddenConsoles()
107 for (
int i=0; i<mDockWidgets.size(); )
109 if (!mDockWidgets[i]->isVisible())
110 this->deleteDockWidget(mDockWidgets[i]);
116 QDockWidget* ConsoleWidgetCollection::addAsDockWidget(QWidget* widget)
118 QDockWidget* dockWidget = this->createDockWidget(widget);
120 mDockWidgets.push_back(dockWidget);
122 connect(dockWidget, &QDockWidget::visibilityChanged,
123 this, &ConsoleWidgetCollection::onDockWidgetVisibilityChanged);
125 this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
129 QDockWidget* ConsoleWidgetCollection::createDockWidget(QWidget* widget)
131 QDockWidget* dockWidget =
new QDockWidget(widget->windowTitle(),
this);
132 connect(widget, &QWidget::windowTitleChanged,
this, &ConsoleWidgetCollection::onConsoleWindowTitleChanged);
133 dockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
134 dockWidget->setObjectName(widget->objectName() +
"DockWidget");
135 dockWidget->setWidget(widget);
139 void ConsoleWidgetCollection::onConsoleWindowTitleChanged(
const QString & title)
141 QWidget* widget =
dynamic_cast<QWidget*
>(sender());
142 QDockWidget* dockWidget =
dynamic_cast<QDockWidget*
>(sender()->parent());
143 if (!widget || !dockWidget)
145 dockWidget->setWindowTitle(widget->windowTitle());
148 void ConsoleWidgetCollection::deleteDockWidget(QDockWidget* dockWidget)
150 disconnect(dockWidget, &QDockWidget::visibilityChanged,
151 this, &ConsoleWidgetCollection::onDockWidgetVisibilityChanged);
153 this->removeDockWidget(dockWidget);
154 mDockWidgets.removeAll(dockWidget);
155 dockWidget->deleteLater();
157 for (
int i=0; i<mDockWidgets.size(); ++i)
159 QString uid = QString(
"ConsoleWidget%1").arg(i);
160 QString dock_uid = uid +
"DockWidget";
161 mDockWidgets[i]->setObjectName(dock_uid);
162 mDockWidgets[i]->widget()->setObjectName(uid);
168 QString uid = QString(
"ConsoleWidget%1").arg(mDockWidgets.size());
170 this->addAsDockWidget(console);
174 void ConsoleWidgetCollection::onNewConsole()
182 this->removeHiddenConsoles();
184 QMenu* popupMenu =
new QMenu(
this);
186 QAction* addConsoleAction =
new QAction(
"New Console",
this);
187 connect(addConsoleAction, &QAction::triggered,
this, &ConsoleWidgetCollection::onNewConsole);
188 popupMenu->addAction(addConsoleAction);
190 for (
int i=0; i<mDockWidgets.size(); ++i)
192 popupMenu->addAction(mDockWidgets[i]->toggleViewAction());
cxResource_EXPORT ProfilePtr profile()
void writeVariant(const QVariant &val)
QDomElement getElement()
return the current element
Helper class for storing one string value in an xml document.
boost::shared_ptr< class Log > LogPtr
QVariant readVariant(const QVariant &defval=QVariant()) const
Helper class for xml files used to store ssc/cx data.
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Namespace for all CustusX production code.