📄 ktmainwindow.cpp
字号:
// left toolbars widest=0; for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next() ) if ( toolbar->barPos() == KToolBar::Left && toolbar->isVisible() ) { toolbar->setMaxHeight(freeHeight); // Sven: You have to do this here toolbar->updateRects (TRUE); // Sven: You have to this widest = (widest>toolbar->width())?widest:toolbar->width(); if ( lo < 0 ) { lo = 0; l += toolbar->width(); toolbar->move( l-toolbar->width(), t + lo ); lo += toolbar->height(); } else if ( lo + toolbar->height() > freeHeight) { lo = 0; l += toolbar->width(); toolbar->move( l-toolbar->width(), t + lo ); lo += toolbar->height(); } else { l=widest; toolbar->move( l-toolbar->width(), t + lo ); lo += toolbar->height(); } } // right toolbars widest=0; for ( toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next() ) if ( toolbar->barPos() == KToolBar::Right && toolbar->isVisible() ) { toolbar->setMaxHeight(freeHeight); // Sven: You have to do this here toolbar->updateRects (TRUE); // Sven: You have to this widest = (widest>toolbar->width())?widest:toolbar->width(); if ( ro < 0 ) { ro = 0; r += toolbar->width(); toolbar->move(w-r, t + ro); ro += toolbar->height(); } else if (ro + toolbar->height() > freeHeight) { ro = 0; r += toolbar->width(); toolbar->move(w-r, t + ro); ro += toolbar->height(); } else { r=widest; toolbar->move(w-r, t + ro); ro += toolbar->height(); } } freeWidth = w-l-r; // set geometry of everything if (kmainwidgetframe) kmainwidgetframe->setGeometry(l, t, freeWidth, freeHeight); if (kmainwidget) kmainwidget->setGeometry(l+borderwidth, t+borderwidth, freeWidth-2*borderwidth, freeHeight-2*borderwidth); // set public variables (for compatibility - kghostview) view_left = l; view_right = width()-r; view_top = t; view_bottom = height()-b; if (fixedY == TRUE) { setMaximumSize(9999, h+t+b); setMinimumSize(kmainwidget->minimumSize().width()+(2*borderwidth)+l+r, h+t+b); resize (width(), h+t+b); // Carefull now! } }}void KTMainWindow::saveData(KConfig*){}void KTMainWindow::saveYourself(){ // Do session management (Matthias) if (kapp->topWidget() != this) return; // According to Jochen Wilhelmy <digisnap@cs.tu-berlin.de>, this // hook is usefull for better document orientation saveData(kapp->getSessionConfig()); QListIterator<KTMainWindow> it(*memberList); int n = 0; KConfig* config = KApplication::getKApplication()->getSessionConfig(); config->setGroup("Number"); config->writeEntry("NumberOfWindows", memberList->count()); for (it.toFirst(); it.current(); ++it){ n++; it.current()->savePropertiesInternal(config, n); } // According to Jochen, config is synced in kapp already // config->sync();}//Matthiasvoid KTMainWindow::savePropertiesInternal (KConfig* config, int number){ QString entry; QStrList entryList; int n = 1; // Tolbar counter. toolbars are counted from 1, // in order they are in toolbar list QString s; s.setNum(number); s.prepend("WindowProperties"); config->setGroup(s); // store the className for later restorating (Matthias) config->writeEntry("ClassName", className()); //use KWM for window properties (Matthias) config->writeEntry("KTWGeometry", KWM::getProperties(winId())); entryList.clear(); if (kstatusbar) { if (kstatusbar->isVisible()) config->writeEntry("StatusBar", "Enabled"); else config->writeEntry("StatusBar", "Disabled"); } if (kmenubar) { if (kmenubar->isVisible()) entryList.append("Enabled"); else entryList.append("Disabled"); switch (kmenubar->menuBarPos()) { case KMenuBar::Flat: //ignore case KMenuBar::Top: entryList.append("Top"); break; case KMenuBar::Bottom: entryList.append("Bottom"); break; case KMenuBar::Floating: entryList.append("Floating"); entryList.append(KWM::getProperties(kmenubar->winId())); break; case KMenuBar::FloatingSystem: entryList.append("FloatingSystem"); break; } config->writeEntry("MenuBar", entryList, ';'); entryList.clear(); } KToolBar *toolbar; QString toolKey; for (toolbar = toolbars.first(); toolbar != 0L; toolbar = toolbars.next()) { if (toolbar->isVisible()) entryList.append("Enabled"); else entryList.append("Disabled"); switch (toolbar->barPos()) { case KToolBar::Flat: //ignore case KToolBar::Top: entryList.append("Top"); break; case KToolBar::Bottom: entryList.append("Bottom"); break; case KToolBar::Left: entryList.append("Left"); break; case KToolBar::Right: entryList.append("Right"); break; case KToolBar::Floating: entryList.append("Floating"); entryList.append(KWM::getProperties(toolbar->winId())); break; } toolKey.setNum(n); toolKey.prepend("ToolBar"); config->writeEntry(toolKey.data(), entryList, ';'); entryList.clear(); n++; } s.setNum(number); config->setGroup(s); saveProperties(config);}//Matthiasbool KTMainWindow::readPropertiesInternal (KConfig* config, int number){ // All comments by sven QString entry; QStrList entryList; int n = 1; // Tolbar counter. toolbars are counted from 1, // in order they are in toolbar list int i = 0; // Number of entries in list QString s; s.setNum(number); s.prepend("WindowProperties"); config->setGroup(s); if (config->hasKey("KTWGeometry") == FALSE) // No global, return False { return FALSE; } // Use KWM for window properties (Matthias) QString geom = config->readEntry ("KTWGeometry"); if (!geom.isEmpty()){ setGeometry(KWM::setProperties(winId(), geom)); } if (kstatusbar) { entry = config->readEntry("StatusBar"); if (entry == "Enabled") enableStatusBar(KStatusBar::Show); else enableStatusBar(KStatusBar::Hide); } if (kmenubar) { i = config->readListEntry ("MenuBar", entryList, ';'); if (i < 2) { //debug ("KTWreadProps: bad number of kmenubar args"); return FALSE; } bool showmenubar = False; //Matthias entry = entryList.first(); if (entry=="Enabled") showmenubar = True; //Matthias else kmenubar->hide(); entry = entryList.next(); if (entry == "Top") kmenubar->setMenuBarPos(KMenuBar::Top); else if (entry == "Bottom") kmenubar->setMenuBarPos(KMenuBar::Bottom); else if (entry == "Floating") { kmenubar->setMenuBarPos(KMenuBar::Floating); entry=entryList.next(); kmenubar->setGeometry(KWM::setProperties(kmenubar->winId(), entry)); showmenubar = true; } else if (entry == "FloatingSystem") { kmenubar->setMenuBarPos(KMenuBar::FloatingSystem); showmenubar = true; } entryList.clear(); if (showmenubar) //Matthias kmenubar->show(); } KToolBar *toolbar; QString toolKey; QListIterator<KToolBar> it(toolbars); // must use own iterator for ( ; it.current(); ++it) { toolbar= it.current(); toolKey.setNum(n); toolKey.prepend("ToolBar"); i = config->readListEntry(toolKey.data(), entryList, ';'); if (i < 2) { //printf ("KTWRP: bad number of toolbar%d args\n", n); return FALSE; } bool showtoolbar = False; //Matthias entry = entryList.first(); if (entry=="Enabled") showtoolbar = True; //Matthias else toolbar->enable(KToolBar::Hide); entry = entryList.next(); if (entry == "Top") toolbar->setBarPos(KToolBar::Top); else if (entry == "Bottom") toolbar->setBarPos(KToolBar::Bottom); else if (entry == "Left") toolbar->setBarPos(KToolBar::Left); else if (entry == "Right") toolbar->setBarPos(KToolBar::Right); else if (entry == "Floating") { toolbar->setBarPos(KToolBar::Floating); entry=entryList.next(); toolbar->setGeometry(KWM::setProperties(toolbar->winId(), entry)); toolbar->updateRects(TRUE); toolbar->show(); } if (showtoolbar) toolbar->enable(KToolBar::Show); //Matthias n++; // next toolbar entryList.clear(); } s.setNum(number); config->setGroup(s); readProperties(config); return True;}void KTMainWindow::setFrameBorderWidth(int size){ borderwidth = size;}//Matthiasbool KTMainWindow::canBeRestored(int number){ if (!kapp->isRestored()) return False; KConfig *config = kapp->getSessionConfig(); if (!config) return False; config->setGroup("Number"); int n = config->readNumEntry("NumberOfWindows", 0); return (number >= 1 && number <= n);}//Matthiasconst QString KTMainWindow::classNameOfToplevel(int number){ if (!kapp->isRestored()) return ""; KConfig *config = kapp->getSessionConfig(); if (!config) return False; QString s; s.setNum(number); s.prepend("WindowProperties"); config->setGroup(s); if (!config->hasKey("ClassName")) return ""; else return config->readEntry("ClassName");}//Matthiasbool KTMainWindow::restore(int number){ if (!canBeRestored(number)) return False; KConfig *config = kapp->getSessionConfig(); if (readPropertiesInternal(config, number)){ show(); return True; } return False;}// Matthiasvoid KTMainWindow::setUnsavedData( bool b){ KWM::setUnsavedDataHint(winId(), b);}void KTMainWindow::resizeEvent( QResizeEvent *ev ){ if (kmainwidget && kmainwidget->minimumSize() == kmainwidget->maximumSize()) return; if (kmainwidget && kmainwidget->minimumSize().height() == kmainwidget->maximumSize().height()) if (ev->oldSize() == ev->size()) return; updateRects();}KStatusBar *KTMainWindow::statusBar(){ if (!kstatusbar) { kstatusbar = new KStatusBar(this); updateRects (); } return kstatusbar;}void KTMainWindow::setStatusBar (KStatusBar *statusbar){ kstatusbar = statusbar; updateRects ();}KMenuBar *KTMainWindow::menuBar(){ if (!kmenubar) { setMenu(new KMenuBar(this)); } return kmenubar;}void KTMainWindow::setMenu (KMenuBar *menubar){ kmenubar = menubar; connect ( kmenubar, SIGNAL( moved (menuPosition) ), this, SLOT( updateRects() ) ); connect (kmenubar, SIGNAL(destroyed ()), this, SLOT(menubarKilled ())); updateRects();}KToolBar *KTMainWindow::toolBar( int ID ){ KToolBar* result = 0; if (ID < int(toolbars.count())) result = toolbars.at( ID ); if (!result) { result = new KToolBar(this); toolbars.append( result ); while (int(toolbars.count()) < ID){ toolbars.append( result ); } connect ( result, SIGNAL( moved (BarPosition) ), this, SLOT( updateRects() ) ); connect (result, SIGNAL(destroyed ()), this, SLOT(toolbarKilled ())); updateRects(); } return result;}void KTMainWindow::enableToolBar( KToolBar::BarStatus stat, int ID ){ KToolBar *t = toolbars.at( ID ); if ( t ) t->enable( stat ); updateRects();}void KTMainWindow::enableStatusBar( KStatusBar::BarStatus stat ){ if ( ( stat == KStatusBar::Toggle && statusBar()->isVisible() ) || stat == KStatusBar::Hide ) statusBar()->hide(); else statusBar()->show(); updateRects();}bool KTMainWindow::hasMenuBar(){ return kmenubar != 0;}bool KTMainWindow::hasStatusBar(){ return kstatusbar != 0;}bool KTMainWindow::hasToolBar( int ID ){ return toolbars.at( ID ) != 0;}void KTMainWindow::menubarKilled(){ if (localKill) { //debug ("KTM: ACK mb kill, local kill, NOT zeroed"); return; } // No dead souls in here. const QObject *dyer = sender (); // Who need last rites? if (dyer) // Doe he live still { kmenubar = 0L; //debug ("KTM: ACK mb kill, zeroed"); }// else// { //debug ("KTM: ACK mb kill, dyer zero, NOT zeroed");// }}void KTMainWindow::toolbarKilled(){ if (localKill) { //debug ("KTM: ACK tb kill, local kill, NOT removed from list"); return; } // No dead souls in here. const QObject *dyer = sender (); // Who need last rites? if (dyer) { toolbars.removeRef((KToolBar *) dyer); // remove it from the list; //debug ("KTM: ACK tb kill, removed from list"); //else //debug ("KTM: ACK tb kill, NOT removed from list"); }// else //debug ("KTM: ACK tb kill, dyer zero, NOT removed from list");}#include "ktmainwindow.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -