MDIView.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <qapplication.h>
00028 # include <qregexp.h>
00029 # include <QEvent>
00030 # include <QCloseEvent>
00031 # include <QMdiSubWindow>
00032 #endif
00033
00034
00035 #include "MDIView.h"
00036 #include "Command.h"
00037 #include "Document.h"
00038 #include "Application.h"
00039 #include "MainWindow.h"
00040
00041 using namespace Gui;
00042
00043 TYPESYSTEM_SOURCE_ABSTRACT(Gui::MDIView,Gui::BaseView);
00044
00045
00046 MDIView::MDIView(Gui::Document* pcDocument,QWidget* parent, Qt::WFlags wflags)
00047 : QMainWindow(parent, wflags), BaseView(pcDocument),currentMode(Child), wstate(Qt::WindowNoState)
00048 {
00049 setAttribute(Qt::WA_DeleteOnClose);
00050 }
00051
00052 MDIView::~MDIView()
00053 {
00054
00055
00056
00057
00058
00059 QWidget* foc = getMainWindow()->focusWidget();
00060 if (foc) {
00061 QWidget* par = foc;
00062 while (par) {
00063 if (par == this) {
00064 getMainWindow()->setFocus();
00065 break;
00066 }
00067 par = par->parentWidget();
00068 }
00069 }
00070 }
00071
00072 void MDIView::deleteSelf()
00073 {
00074
00075
00076 #if !defined (NO_USE_QT_MDI_AREA)
00077 QWidget* parent = this->parentWidget();
00078 if (qobject_cast<QMdiSubWindow*>(parent))
00079 delete parent;
00080 else
00081 #endif
00082 delete this;
00083 }
00084
00085 void MDIView::onRelabel(Gui::Document *pDoc)
00086 {
00087 if (!bIsPassive) {
00088
00089 QString cap = windowTitle();
00090
00091 QRegExp rx(QLatin1String("(\\s\\:\\s\\d+\\[\\*\\])$"));
00092 int pos = rx.lastIndexIn(cap);
00093 if (pos == -1) {
00094
00095 rx.setPattern(QLatin1String("(\\s\\:\\s\\d+)$"));
00096 pos = rx.lastIndexIn(cap);
00097 }
00098 if (pos != -1) {
00099 cap = QString::fromUtf8(pDoc->getDocument()->Label.getValue());
00100 cap += rx.cap();
00101 setWindowTitle(cap);
00102 }
00103 else {
00104 cap = QString::fromUtf8(pDoc->getDocument()->Label.getValue());
00105 cap = QString::fromAscii("%1[*]").arg(cap);
00106 setWindowTitle(cap);
00107 }
00108 }
00109 }
00110
00111 void MDIView::viewAll()
00112 {
00113 }
00114
00116 bool MDIView::onMsg(const char* pMsg,const char** ppReturn)
00117 {
00118 return false;
00119 }
00120
00121 bool MDIView::onHasMsg(const char* pMsg) const
00122 {
00123 return false;
00124 }
00125
00126 bool MDIView::canClose(void)
00127 {
00128 if (!bIsPassive && getGuiDocument() && getGuiDocument()->isLastView()) {
00129 this->setFocus();
00130 return (getGuiDocument()->canClose());
00131 }
00132
00133 return true;
00134 }
00135
00136 void MDIView::closeEvent(QCloseEvent *e)
00137 {
00138 if (canClose()) {
00139 e->accept();
00140 if (!bIsPassive) {
00141
00142 Document* doc = this->getGuiDocument();
00143 if (doc && !doc->isLastView())
00144 doc->detachView(this);
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 #if defined (NO_USE_QT_MDI_AREA)
00156
00157 getMainWindow()->removeWindow(this);
00158 #endif
00159 QMainWindow::closeEvent(e);
00160 }
00161 else
00162 e->ignore();
00163 }
00164
00165 void MDIView::windowStateChanged( MDIView* )
00166 {
00167 }
00168
00169 void MDIView::print()
00170 {
00171
00172 assert(0);
00173 }
00174
00175 void MDIView::printPdf()
00176 {
00177
00178 assert(0);
00179 }
00180
00181 void MDIView::printPreview()
00182 {
00183
00184 assert(0);
00185 }
00186
00187 QSize MDIView::minimumSizeHint () const
00188 {
00189 return QSize(400, 300);
00190 }
00191
00192 void MDIView::changeEvent(QEvent *e)
00193 {
00194 switch (e->type()) {
00195 case QEvent::ActivationChange:
00196 {
00197
00198 if (isActiveWindow()) {
00199 if (getMainWindow()->activeWindow() != this)
00200 getMainWindow()->setActiveWindow(this);
00201 }
00202 } break;
00203 case QEvent::WindowTitleChange:
00204 case QEvent::ModifiedChange:
00205 {
00206
00207 getMainWindow()->tabChanged(this);
00208 } break;
00209 default:
00210 {
00211 QMainWindow::changeEvent(e);
00212 } break;
00213 }
00214 }
00215
00216 #if defined(Q_WS_X11)
00217
00218 extern void qt_x11_wait_for_window_manager( QWidget* w );
00219 #endif
00220
00221 void MDIView::setCurrentViewMode(ViewMode mode)
00222 {
00223 switch (mode) {
00224
00225 case Child:
00226 {
00227 if (this->currentMode == FullScreen) {
00228 showNormal();
00229 setWindowFlags(windowFlags() & ~Qt::Window);
00230 }
00231 else if (this->currentMode == TopLevel) {
00232 this->wstate = windowState();
00233 setWindowFlags( windowFlags() & ~Qt::Window );
00234 }
00235
00236 if (this->currentMode != Child) {
00237 this->currentMode = Child;
00238 getMainWindow()->addWindow(this);
00239 getMainWindow()->activateWindow();
00240 update();
00241 }
00242 } break;
00243
00244 case TopLevel:
00245 {
00246 if (this->currentMode == Child) {
00247 #if !defined (NO_USE_QT_MDI_AREA)
00248 if (qobject_cast<QMdiSubWindow*>(this->parentWidget()))
00249 #endif
00250 getMainWindow()->removeWindow(this);
00251 setWindowFlags(windowFlags() | Qt::Window);
00252 setParent(0, Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
00253 Qt::WindowMinMaxButtonsHint);
00254 if (this->wstate & Qt::WindowMaximized)
00255 showMaximized();
00256 else
00257 showNormal();
00258
00259 #if defined(Q_WS_X11)
00260
00261 qt_x11_wait_for_window_manager(this);
00262 #endif
00263 activateWindow();
00264 }
00265 else if (this->currentMode == FullScreen) {
00266 if (this->wstate & Qt::WindowMaximized)
00267 showMaximized();
00268 else
00269 showNormal();
00270 }
00271
00272 this->currentMode = TopLevel;
00273 update();
00274 } break;
00275
00276 case FullScreen:
00277 {
00278 if (this->currentMode == Child) {
00279 #if !defined (NO_USE_QT_MDI_AREA)
00280 if (qobject_cast<QMdiSubWindow*>(this->parentWidget()))
00281 #endif
00282 getMainWindow()->removeWindow(this);
00283 setWindowFlags(windowFlags() | Qt::Window);
00284 setParent(0, Qt::Window);
00285 showFullScreen();
00286 }
00287 else if (this->currentMode == TopLevel) {
00288 this->wstate = windowState();
00289 showFullScreen();
00290 }
00291
00292 this->currentMode = FullScreen;
00293 update();
00294 } break;
00295 }
00296 }
00297
00298 #include "moc_MDIView.cpp"