📄 knotebook.cpp
字号:
pnote->enablearrowbuttons = state; for(int i = 0; i < pnote->numtabs; i++) sections->at(i)->setEnableArrowButtons(state);}bool KNoteBook::enableArrowButtons(){ return pnote->enablearrowbuttons;}void KNoteBook::setDirectionsReflectsPage(bool state){ pnote->directionsreflectspage = state; for(int i = 0; i < pnote->numtabs; i++) sections->at(i)->setDirectionsReflectsPage(state); setSizes();}bool KNoteBook::directionsReflectsPage(){ return pnote->directionsreflectspage;}void KNoteBook::setEnablePopupMenu(bool state){ pnote->enablepopupmenu = state;}bool KNoteBook::enablePopupMenu(){ return pnote->enablepopupmenu;}QPopupMenu *KNoteBook::getMenu(){ return pnote->menu;}KTabBar *KNoteBook::getTabBar(){ return pnote->tabbar;}void KNoteBook::setTabEnabled(int tab, bool state){ pnote->tabbar->setTabEnabled( tab, state ); pnote->menu->setItemEnabled( tab, state );}void KNoteBook::setPageEnabled(int tab, int page, bool state){ sections->at(tab)->setPageEnabled( page, state );}bool KNoteBook::isTabEnabled(int tab){ return pnote->tabbar->isTabEnabled(tab);}bool KNoteBook::isPageEnabled(int tab, int page){ return sections->at(tab)->isPageEnabled(page);}int KNoteBook::numTabs(){ return pnote->numtabs;}void KNoteBook::directionButton(bool changetab, bool forward){ //debug("directionButton"); QButton *button, *arrow; QString str; if(changetab) { if(forward) { //debug("changing to tab: %d", current+1); gotoTab(pnote->current+1); button = pnote->currentwiz->getPreviousButton(); arrow = pnote->currentwiz->getLeftArrow(); if(pnote->directionsreflectspage) { str = "<< "; str += sections->at(pnote->current-1)->getTitle(sections->at(pnote->current-1)->numPages()-1); button->setText(str.data()); } else button->setText(PREV); //debug("Setting previous to: %s", str.data()); button->show(); if(pnote->enablearrowbuttons) arrow->show(); } else { //debug("changing to tab: %d", pnote->current-1); gotoTab(pnote->current-1); pnote->currentwiz->gotoPage(pnote->currentwiz->numPages()-1); button = pnote->currentwiz->getNextButton(); arrow = pnote->currentwiz->getRightArrow(); if(pnote->directionsreflectspage) { str = sections->at(pnote->current+1)->getTitle(0); str += " >>"; button->setText(str.data()); } else button->setText(NEXT); //debug("Setting next to: %s", str.data()); button->show(); if(pnote->enablearrowbuttons) arrow->show(); } } else { //debug("dont change tab"); if(forward) { button = pnote->currentwiz->getNextButton(); arrow = pnote->currentwiz->getRightArrow(); if((pnote->current+1) >= pnote->numtabs) { button->hide(); if(pnote->enablearrowbuttons) arrow->hide(); } else { str = sections->at(pnote->current+1)->getTitle(0); str += " >>"; //debug("Setting next to: %s", str.data()); button->setText(str.data()); button->show(); if(pnote->enablearrowbuttons) arrow->show(); } } else { button = pnote->currentwiz->getPreviousButton(); arrow = pnote->currentwiz->getLeftArrow(); if((pnote->current) == 0) { button->hide(); if(pnote->enablearrowbuttons) arrow->hide(); } else { str = "<< "; str += sections->at(pnote->current-1)->getTitle(sections->at(pnote->current-1)->numPages()-1); //debug("Setting previous to: %s", str.data()); button->setText(str.data()); button->show(); if(pnote->enablearrowbuttons) arrow->show(); } } }}void KNoteBook::setSizes(){ //debug("setSizes"); QSize childsize = childSize(); int extra = 16; bool f = false; if(pnote->ok) { pnote->ok->adjustSize(); f = true; extra += pnote->ok->height(); } if(pnote->cancel) { pnote->cancel->adjustSize(); if(!f) { f = true; extra += pnote->cancel->height(); } } if(pnote->def) { pnote->def->adjustSize(); if(!f) { f = true; extra += pnote->def->height(); } } if(pnote->help) { pnote->help->adjustSize(); if(!f) extra += pnote->help->height(); } pnote->tabbar->adjustSize(); int y = pnote->tabbar->height() + childsize.height() + extra; int x = 16 + childsize.width(); setMinimumSize(x, y); resize(x, y); //debug("setSizes - done");}void KNoteBook::resizeEvent(QResizeEvent *){ //debug("KNote, resizing"); pnote->tabbar->setGeometry( 2, 2, width()-3, pnote->tabbar->sizeHint().height()); // Check to see if there are any buttons. QPushButton *tmp = 0L; int x = 8, y = pnote->tabbar->height() + 7; int cx = width() - 14, cy = height()-(pnote->tabbar->height()+14); if( pnote->ok && pnote->ok->isVisible() ) tmp = pnote->ok; else if(pnote->cancel && pnote->cancel->isVisible()) tmp = pnote->cancel; else if(pnote->def && pnote->def->isVisible()) tmp = pnote->def; else if(pnote->help && pnote->help->isVisible()) tmp = pnote->help; if(tmp) cy -= (tmp->height()); if(pnote->currentwiz) pnote->currentwiz->setGeometry( x, y, cx, cy ); int offs = 2; if(pnote->ok && pnote->ok->isVisible()) { pnote->ok->setGeometry(offs, height()-(pnote->ok->height()+2), pnote->ok->width(), pnote->ok->height()); offs += 5 + pnote->ok->width(); } if(pnote->cancel && pnote->cancel->isVisible()) { pnote->cancel->setGeometry(offs, height()-(pnote->cancel->height()+2), pnote->cancel->width(), pnote->cancel->height()); offs += 5 + pnote->cancel->width(); } if(pnote->def && pnote->def->isVisible()) pnote->def->setGeometry(offs, height()-(pnote->def->height()+2), pnote->def->width(), pnote->def->height()); if(pnote->help && pnote->help->isVisible()) pnote->help->setGeometry(width()-(pnote->help->width()+1), height()-(pnote->help->height()+2), pnote->help->width(), pnote->help->height()); //debug("KNote, resize - done");}void KNoteBook::paintEvent(QPaintEvent *){ //debug("KNoteBook::paintEvent"); // Check to see if there are any buttons. QPushButton *tmp = 0L; int w = width(), h = height(), s = 2; int tw = pnote->tabbar->width(); int boffs = 4, toffs = pnote->tabbar->height() + 1; if( pnote->ok && pnote->ok->isVisible() ) tmp = pnote->ok; else if(pnote->cancel && pnote->cancel->isVisible()) tmp = pnote->cancel; else if(pnote->def && pnote->def->isVisible()) tmp = pnote->def; else if(pnote->help && pnote->help->isVisible()) tmp = pnote->help; if(tmp) boffs = tmp->height() + 4; // start painting widget QPainter paint; paint.begin( this ); QPen pen( white, 1 ); paint.setPen( pen ); // left outer paint.drawLine( s, h-(boffs), s, toffs-1); // top outer paint.drawLine( tw+s , toffs, w-s, toffs); // right inner paint.drawLine( w-(s*3) , toffs+(s*2)+1, w-(s*3), h-(boffs+(s+1))); // bottom inner paint.drawLine( (s*3)+1 , h-(boffs+(s*2)-1), w-(s*3), h-(boffs+(s*2)-1)); pen.setColor( black ); paint.setPen( pen ); // right outer paint.drawLine( w-s , toffs+1, w-s, h-(boffs)); // bottom outer paint.drawLine( w-s , h-(boffs), s+1, h-(boffs)); // left inner paint.drawLine( s*3 , h-(boffs+(s+1)), s*3, toffs+((s*2)+1) ); // top inner paint.drawLine( (s*3)+1, toffs+(s*2), w-(s*3), toffs+(s*2)); paint.end();}/*// Grab QDialogs keypresses if non-modalbool KNoteBook::eventFilter( QObject *obj, QEvent *e ){ if ( e->type() == Event_KeyPress && obj == this && !testWFlags(WType_Modal)) { QKeyEvent *k = (QKeyEvent*)e; if(k->key() == Key_Escape || k->key() == Key_Return || k->key() == Key_Enter) return true; } return false;}*/#include "knotebook.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -