📄 ktoolbar.cpp
字号:
// debug ("KToolBar destructor: about to recreate");// recreate (Parent, oldWFlags, QPoint (oldX, oldY), false);// debug ("KToolBar destructor: recreated");// } // what is that?! toolbaritems are children of the toolbar, which // means, qt will delete them for us (Matthias) //for ( KToolBarItem *b = items.first(); b!=0L; b=items.next() ) // items.remove(); //Uhh... I'm embaresd... (sven) // I would never guess that (sven) if (!QApplication::closingDown()) delete context; //debug ("KToolBar destructor");}void KToolBar::setMaxHeight (int h){ max_height = h;}void KToolBar::setMaxWidth (int w){ max_width = w; updateRects(true);}void KToolBar::layoutHorizontal (){ int offset=3+9+4; // = 16 int rightOffset; int yOffset=1; KToolBarItem *autoSize = 0; int mywidth; int widest=0; horizontal = true; // sven - 040198 //debug ("Ho, ho, hooo... Up-Date!!! (horizontal)"); if (position == Floating) if (haveAutoSized == false) mywidth = width(); else mywidth = (width()>MIN_AUTOSIZE+offset)?width():MIN_AUTOSIZE+offset; else if (max_width != -1) mywidth = max_width; else mywidth = Parent->width(); if (fullWidth == true) toolbarWidth = mywidth; else toolbarWidth = offset; rightOffset=mywidth; toolbarHeight= item_size; for ( KToolBarItem *b = items.first(); b; b=items.next() ) { if (b->isAuto()) widest = (MIN_AUTOSIZE>widest)?MIN_AUTOSIZE:widest; else widest = (b->width()>widest)?b->width():widest; if (fullWidth == true) { if (b->isRight() == true) { rightOffset=rightOffset-3-b->width(); if (rightOffset <= (offset+3)) { yOffset += item_size; toolbarHeight += item_size; } XMoveWindow(qt_xdisplay(), b->winId(), rightOffset, yOffset); b->move (rightOffset, yOffset); } else // Not right { int myWidth = 0; if (b->isAuto() == true) { autoSize = b; myWidth = MIN_AUTOSIZE; // Min width for autosized } else myWidth = b->width(); if (offset > (rightOffset-myWidth+3)) { offset =3+4+9; yOffset += item_size; toolbarHeight += item_size; } // Put it *really* *really* there! // This is a workaround for a Qt-1.32 bug. XMoveWindow(qt_xdisplay(), b->winId(), offset, yOffset); // This is what *should* be sufficient b->move( offset, yOffset ); offset += myWidth + 3; } } else // Not fullwidth, autosize { if (offset > (mywidth-b->width()-3) && offset != 16) { offset = 3+9+4; yOffset += item_size; toolbarHeight += item_size; XMoveWindow(qt_xdisplay(), b->winId(), offset, yOffset); b->move( offset, yOffset ); offset += b->width()+3; } else { XMoveWindow(qt_xdisplay(), b->winId(), offset, yOffset); b->move( offset, yOffset ); offset += b->width()+3; if (offset > toolbarWidth) toolbarWidth = offset; } } } if (autoSize != 0) autoSize->resize(rightOffset - autoSize->x()-1, autoSize->height() ); toolbarWidth=(toolbarWidth<(widest+16))?(widest+16):toolbarWidth;}void KToolBar::layoutVertical (){ int offset=3+9+4; int yOffset=3; int widest; horizontal=false; // sven - 040198 //debug ("Ho, ho, hooo... Up-Date!!! (vertical)"); toolbarHeight = offset; toolbarWidth= item_size; widest = item_size; // I have (had) ten thousand problems here.... for ( KToolBarItem *b = items.first(); b; b=items.next() ) { if (offset > ((max_height)-(b->height()+3))) { offset = 4+9+3; yOffset += widest; toolbarWidth += item_size; // Put it *really* *really* there! // This is a workaround for a Qt-1.32 bug. XMoveWindow(qt_xdisplay(), b->winId(), yOffset, offset); b->move( yOffset, offset ); if (b->isAuto() == true) b->resize ((widest>MIN_AUTOSIZE)?widest:MIN_AUTOSIZE, b->height()); if ((yOffset + b->width()+3) > toolbarWidth) // is item wider than we are toolbarWidth = b->width() +yOffset+2; if ((b->width() +3) > widest) widest =(b->width() +3); offset += b->height()+3; } else { // Put it *really* *really* there! // This is a workaround for a Qt-1.32 bug. XMoveWindow(qt_xdisplay(), b->winId(), yOffset, offset); b->move( yOffset, offset ); if (b->isAuto() == true) b->resize ((widest>MIN_AUTOSIZE)?widest:MIN_AUTOSIZE, b->height()); if ((yOffset + b->width()+3) > toolbarWidth) // is item wider than we are toolbarWidth = b->width() +yOffset+2; if ((b->width() +3) > widest) widest =(b->width() +3); offset += b->height()+3; if (offset > toolbarHeight) toolbarHeight = offset; } }}void KToolBar::updateRects( bool res ){ switch ( position ) { case Top: case Bottom: layoutHorizontal (); break; case Floating: max_height = height(); if (items.count() == 0) layoutHorizontal (); else if (width() <= height ()-10) layoutVertical (); else if(width() >= height ()+10) layoutHorizontal (); break; case Left: case Right: layoutVertical (); break; } if (res == true) { localResize = true; resize (toolbarWidth, toolbarHeight); localResize = false; } /* I needed to call processEvents () to flush pending resizeEvent after doing resize from here so that resizeEvent () sees the semaphore localResize. After examining qt source, I saw that QWidget::resize() calls QApplication::sendEvent() which, as far as I understand, notifies this->resizeEvent() immediatelly, without waiting. Even worse - it seems that it really works. "Worse?", I hear you asking. Yes, even worse indeed it is, because I lost my mind trying to get rid of excess resizes, and now they vanished mysteriously all by itself (all except two) */}void KToolBar::mousePressEvent ( QMouseEvent *m ){ if ((horizontal && m->x()<9) || (!horizontal && m->y()<9)) { pointerOffset = m->pos(); if (moving) if (m->button() == RightButton) { context->popup( mapToGlobal( m->pos() ), 0 ); ContextCallback(0); } else if (m->button() == MidButton && position != Floating) setFlat (position != Flat); else if (position != Flat) toggleFlatOnRelease=true; }}void KToolBar::slotHotSpot(int hs){ if (mgr == 0) return; if (!transparent) // opaque { switch (hs) { case 0: //top setBarPos(Top); break; case 1: //bottom setBarPos(Bottom); break; case 2: //left setBarPos(Left); break; case 3: //right setBarPos(Right); break; case -1: // left all setBarPos(Floating); break; } if (position != Floating) { QPoint p(Parent->mapToGlobal(pos())); // OH GOOOOODDDD!!!!! mgr->setGeometry(p.x(), p.y(), width(), height()); } if (!isVisible()) show(); } else // transparent { switch (hs) { case 0: //top mgr->setGeometry(0); movePos=Top; break; case 1: //bottom mgr->setGeometry(1); movePos=Bottom; break; case 2: //left mgr->setGeometry(2); movePos=Left; break; case 3: //right mgr->setGeometry(3); movePos=Right; break; case -1: // left all mgr->setGeometry(mgr->mouseX(), mgr->mouseY(), width(), height()); movePos=Floating; break; } }}void KToolBar::resizeEvent( QResizeEvent *){ /* Newest - sven */ if (position == Floating) // are we floating? If yes... if (!localResize) // call from updateRects? if *_NOT_*... updateRects(true); // ...update (i.e. WM resized us)}void KToolBar::paintEvent(QPaintEvent *){ if (mgr) return; //MD Lots of rewrite // This code should be shared with the aequivalent in kmenubar! // (Marcin Dalecki). toolbarHeight = height (); toolbarWidth = width (); int stipple_height; QColorGroup g = QWidget::colorGroup(); QPainter *paint = new QPainter(); paint->begin( this ); if (moving) { // Took higlighting handle from kmenubar - sven 040198 QBrush b; if (mouseEntered && highlight) b = kapp->selectColor; // this is much more logical then // the hardwired value used before!! else b = QWidget::backgroundColor(); // Handle point if (horizontal) { if (style() == MotifStyle) { qDrawShadePanel( paint, 0, 0, 9, toolbarHeight, g , false, 1, &b); paint->setPen( g.light() ); if (style() == MotifStyle) paint->drawLine( 9, 0, 9, toolbarHeight); stipple_height = 3; while ( stipple_height < toolbarHeight-4 ) { paint->drawPoint( 1, stipple_height+1); paint->drawPoint( 4, stipple_height); stipple_height+=3; } paint->setPen( g.dark() ); stipple_height = 4; while ( stipple_height < toolbarHeight-4 ) { paint->drawPoint( 2, stipple_height+1); paint->drawPoint( 5, stipple_height); stipple_height+=3; } } else // Windows style handle { int w = 6; int h = toolbarHeight; paint->setClipRect(0, 2, w, h-4); qDrawPlainRect ( paint, 0, 0, 9, toolbarHeight, g.mid(), 0, &b); paint->setPen( g.light() ); int a=0-w; while (a <= h+5) { paint->drawLine(0, h-a, h, 0-a); paint->drawLine(0, h-a+1, h, 0-a+1); a +=6; } a=0-w; paint->setPen( g.dark() ); while (a <= h+5) { paint->drawLine(0, h-a+2, h, 0-a+2); paint->drawLine(0, h-a+3, h, 0-a+3); a +=6; } } } else // vertical { if (style() == MotifStyle) { qDrawShadePanel( paint, 0, 0, toolbarWidth, 9, g , false, 1, &b); paint->setPen( g.light() ); if (style() == MotifStyle) paint->drawLine( 0, 9, toolbarWidth, 9); stipple_height = 3; while ( stipple_height < toolbarWidth-4 ) { paint->drawPoint( stipple_height+1, 1); paint->drawPoint( stipple_height, 4 ); stipple_height+=3; } paint->setPen( g.dark() ); stipple_height = 4; while ( stipple_height < toolbarWidth-4 ) { paint->drawPoint( stipple_height+1, 2 ); paint->drawPoint( stipple_height, 5); stipple_height+=3; } } else { qDrawPlainRect( paint, 0, 0, toolbarWidth, 9, g.mid(), 0, &b); int w = toolbarWidth; int h = 15; paint->setClipRect(2, 0, w-4, 6); //qDrawPlainRect ( paint, 0, 0, 9, toolbarHeight, // g.mid(), 0, &b); paint->setPen( g.light() ); int a = 0-h; while (a <= w+h) { paint->drawLine(w-a, h, w-a+h, 0); paint->drawLine(w-a+1, h, w-a+1+h, 0); a +=6; } a = 0-h; paint->setPen( g.dark() ); while (a <= w+h) { paint->drawLine(w-a+2, h, w-a+2+h, 0); paint->drawLine(w-a+3, h, w-a+3+h, 0); a +=6; } } } } //endif moving if (position != Floating) if ( style() == MotifStyle ) qDrawShadePanel(paint, 0, 0, width(), height(), g , false, 1); //else //qDrawShadeRect(paint, 0, 0, width(), height(), g , true, 1); paint->end(); delete paint;}void KToolBar::closeEvent (QCloseEvent *e){ if (position == Floating) { setBarPos(lastPosition); e->ignore(); return; } e->accept();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -