35 #include <QDockWidget> 42 #include <QDataStream> 51 QMainWindow(parent), mObjectName(objectName), mWindowTitle(windowTitle)
53 this->setObjectName(mObjectName);
54 this->setWindowTitle(mWindowTitle);
62 QMainWindow(parent), mObjectName(objectName), mWindowTitle(windowTitle)
64 this->setObjectName(mObjectName);
65 this->setWindowTitle(mWindowTitle);
66 mOptions =
profile()->getXmlSettings().descend(this->objectName());
72 void ConsoleWidgetCollection::setupUI()
74 this->setFocusPolicy(Qt::StrongFocus);
76 this->setDockNestingEnabled(
true);
77 this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
79 int consoleCount = this->option(
"consoleCount").
readVariant(-1).toInt();
81 for (
int i=0; i<consoleCount; ++i)
89 this->restoreState(this->option(
"windowState").readVariant().toByteArray());
92 if (mDockWidgets.empty())
106 this->option(
"windowState").
writeVariant(this->saveState());
107 this->option(
"consoleCount").
writeVariant(QVariant::fromValue<int>(mDockWidgets.size()));
110 void ConsoleWidgetCollection::onDockWidgetVisibilityChanged(
bool val)
112 if (!this->isVisible())
118 QTimer::singleShot(0,
this, SLOT(checkVisibility()));
121 void ConsoleWidgetCollection::checkVisibility()
123 this->removeHiddenConsoles();
126 void ConsoleWidgetCollection::removeHiddenConsoles()
128 for (
int i=0; i<mDockWidgets.size(); )
130 if (!mDockWidgets[i]->isVisible())
131 this->deleteDockWidget(mDockWidgets[i]);
137 QDockWidget* ConsoleWidgetCollection::addAsDockWidget(QWidget* widget)
139 QDockWidget* dockWidget = this->createDockWidget(widget);
141 mDockWidgets.push_back(dockWidget);
143 connect(dockWidget, &QDockWidget::visibilityChanged,
144 this, &ConsoleWidgetCollection::onDockWidgetVisibilityChanged);
146 this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
150 QDockWidget* ConsoleWidgetCollection::createDockWidget(QWidget* widget)
152 QDockWidget* dockWidget =
new QDockWidget(widget->windowTitle(),
this);
153 connect(widget, &QWidget::windowTitleChanged,
this, &ConsoleWidgetCollection::onConsoleWindowTitleChanged);
154 dockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
155 dockWidget->setObjectName(widget->objectName() +
"DockWidget");
156 dockWidget->setWidget(widget);
160 void ConsoleWidgetCollection::onConsoleWindowTitleChanged(
const QString & title)
162 QWidget* widget =
dynamic_cast<QWidget*
>(sender());
163 QDockWidget* dockWidget =
dynamic_cast<QDockWidget*
>(sender()->parent());
164 if (!widget || !dockWidget)
166 dockWidget->setWindowTitle(widget->windowTitle());
169 void ConsoleWidgetCollection::deleteDockWidget(QDockWidget* dockWidget)
171 disconnect(dockWidget, &QDockWidget::visibilityChanged,
172 this, &ConsoleWidgetCollection::onDockWidgetVisibilityChanged);
174 this->removeDockWidget(dockWidget);
175 mDockWidgets.removeAll(dockWidget);
176 dockWidget->deleteLater();
178 for (
int i=0; i<mDockWidgets.size(); ++i)
180 QString uid = QString(
"ConsoleWidget%1").arg(i);
181 QString dock_uid = uid +
"DockWidget";
182 mDockWidgets[i]->setObjectName(dock_uid);
183 mDockWidgets[i]->widget()->setObjectName(uid);
189 QString uid = QString(
"ConsoleWidget%1").arg(mDockWidgets.size());
191 this->addAsDockWidget(console);
195 void ConsoleWidgetCollection::onNewConsole()
203 this->removeHiddenConsoles();
205 QMenu* popupMenu =
new QMenu(
this);
207 QAction* addConsoleAction =
new QAction(
"New Console",
this);
208 connect(addConsoleAction, &QAction::triggered,
this, &ConsoleWidgetCollection::onNewConsole);
209 popupMenu->addAction(addConsoleAction);
211 for (
int i=0; i<mDockWidgets.size(); ++i)
213 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.