📄 ktoolbar.cpp
字号:
for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) { ((KCombo *) b->getItem())->insertItem(text, index); ((KCombo *) b->getItem())->cursorAtEnd(); }}void KToolBar::insertComboList (int id, QStrList *list, int index){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) ((KCombo *) b->getItem())->insertStrList(list, index);}void KToolBar::setCurrentComboItem (int id, int index){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) { ((KCombo *) b->getItem())->setCurrentItem(index); ((KCombo *) b->getItem())->cursorAtEnd(); }}void KToolBar::removeComboItem (int id, int index){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) ((KCombo *) b->getItem())->removeItem(index);}void KToolBar::changeComboItem (int id, const char *text, int index){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) { if (index == -1) { index = ((KCombo *) b->getItem())->currentItem(); ((KCombo *) b->getItem())->changeItem(text, index); } else { ((KCombo *) b->getItem())->changeItem(text, index); } ((KCombo *) b->getItem())->cursorAtEnd(); }}void KToolBar::clearCombo (int id){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) ((KCombo *) b->getItem())->clear();}const char *KToolBar::getComboItem (int id, int index){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) { if (index == -1) index = ((KCombo *) b->getItem())->currentItem(); return ((KCombo *) b->getItem())->text(index); } return 0;}KCombo *KToolBar::getCombo (int id){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) return ((KCombo *) b->getItem()); return 0;}KLined *KToolBar::getLined (int id){ for (KToolBarItem *b = items.first(); b!=NULL; b=items.next()) if (b->ID() == id ) return ((KLined *) b->getItem()); return 0;}KToolBarButton* KToolBar::getButton( int id ){ for( KToolBarItem* b = items.first(); b != NULL; b = items.next() ) if(b->ID() == id ) return ((KToolBarButton *) b->getItem()); return 0;}QFrame *KToolBar::getFrame (int id){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) return ((QFrame *) b->getItem()); return 0;}QWidget *KToolBar::getWidget (int id){ for (KToolBarItem *b = items.first(); b; b=items.next()) if (b->ID() == id ) return (b->getItem()); return 0;}/// Toolbar itselfvoid KToolBar::setFullWidth(bool flag){ fullWidth = flag;}void KToolBar::enableMoving(bool flag){ moving = flag; }void KToolBar::setBarPos(BarPosition bpos){ if (position != bpos) { if (bpos == Floating) { lastPosition = position; position = bpos; oldX = x(); oldY = y(); oldWFlags = getWFlags(); QPoint p = mapToGlobal(QPoint(0,0)); parentOffset = pos(); hide(); recreate(0, 0, p, false); XSetTransientForHint( qt_xdisplay(), winId(), Parent->topLevelWidget()->winId()); KWM::setDecoration(winId(), 2); KWM::moveToDesktop(winId(), KWM::desktop(Parent->winId())); setCaption(""); // this triggers a qt bug if (title){ setCaption(title); } else { QString s = Parent->caption(); s.append(" [tools]"); setCaption(s); } context->changeItem (klocale->translate("UnFloat"), CONTEXT_FLOAT); setMouseTracking(true); mouseEntered=false; wasFullWidth=fullWidth; if (!haveAutoSized) //if we don't have autosized item fullWidth=false; // turn off autosize of toolbar else // but if we do.. resize((int) (0.7*width()), height()); // narrow us on 70% updateRects (true); // we need this to set us up emit moved (bpos); // this sets up KTW but not toolbar which floats setMinimumSize (item_size, item_size); return; } else if (position == Floating) // was floating { position = bpos; hide(); recreate(Parent, oldWFlags, QPoint(oldX, oldY), true); setMinimumSize (30,10); // for flat context->changeItem (klocale->translate("Float"), CONTEXT_FLOAT); setMouseTracking(true); mouseEntered = false; fullWidth=wasFullWidth; // updateRects (true); emit moved (bpos); // another bar::updateRects (damn) No! It's ok. return; } else { if (bpos == Flat) { setFlat (true); return; } position = bpos; enableFloating (true); emit moved ( bpos ); return; } }}void KToolBar::enableFloating (bool arrrrrrgh){ context->setItemEnabled (CONTEXT_FLOAT, arrrrrrgh);}void KToolBar::setIconText(int icontext){ bool doUpdate=false; if (icontext != icon_text) { icon_text=icontext; doUpdate=true; } if (doUpdate) emit modechange(); // tell buttons what happened if (isVisible ()) emit moved (position);}bool KToolBar::enable(BarStatus stat){ bool mystat = isVisible(); if ( (stat == Toggle && mystat) || stat == Hide ) { //if (position == Floating) //iconify(); //else hide(); //Sven 09.12.1998: hide in both cases } else show(); return ( isVisible() == mystat );}QSize KToolBar::sizeHint (){ int w=16; for (KToolBarItem *b = items.first(); b; b=items.next()) { w+=b->isAuto()?MIN_AUTOSIZE:b->width(); w+=3; } szh.setWidth(w); return szh;}/*************************************************************Mouse move and drag routines*************************************************************/void KToolBar::leaveEvent (QEvent *){ if (mgr) return; mouseEntered = false; repaint();}void KToolBar::mouseMoveEvent(QMouseEvent* mev){ if (mgr) return; // Handle highlighting - sven 050198 if (horizontal) if (mev->x() < 9) { if (!mouseEntered) { mouseEntered = true; repaint(); } } else { if (mouseEntered) { mouseEntered = false; repaint(); } } else if (mev->y() < 9) { if (!mouseEntered) { mouseEntered = true; repaint(); } } else { if (mouseEntered) { mouseEntered = false; repaint(); } } // LMB flatUnFlat thing if (mev->state() == LeftButton) { if (toggleFlatOnRelease) { toggleFlatOnRelease=false; int ox, oy, ow, oh; //QRect rr(KWM::geometry(Parent->winId(), false)); QRect rr(Parent->geometry()); ox = rr.x(); oy = rr.y(); ow = rr.width(); oh = rr.height(); if (Parent->inherits("KTMainWindow")) { ox += ((KTopLevelWidget *) Parent)->view_left; oy += ((KTopLevelWidget *) Parent)->view_top; ow = ((KTopLevelWidget *) Parent)->view_right - ((KTopLevelWidget *) Parent)->view_left; oh = ((KTopLevelWidget *) Parent)->view_bottom - ((KTopLevelWidget *) Parent)->view_top;; } int fat = 25; //ness mgr = new KToolBoxManager(this, transparent); //Firt of all discover _your_ position if (position == Top ) mgr->addHotSpot(geometry(), true); // I'm on top else mgr->addHotSpot(rr.x(), oy, rr.width(), fat); // top if (position == Bottom) mgr->addHotSpot(geometry(), true); // I'm on bottom else mgr->addHotSpot(rr.x(), oy+oh-fat, rr.width(), fat); // bottom if (position == Left) mgr->addHotSpot(geometry(), true); // I'm on left else mgr->addHotSpot(ox, oy, fat, oh); // left if (position == Right) mgr->addHotSpot(geometry(), true); // I'm on right else mgr->addHotSpot(ox+ow-fat, oy, fat, oh); //right /* mgr->addHotSpot(ox, oy, ow, fat); // top mgr->addHotSpot(ox, oy+oh-fat, ow, fat); // bottom mgr->addHotSpot(ox, oy+fat, fat, oh-2*fat); // left mgr->addHotSpot(ox+ow-fat, oy+fat, fat, oh-2*fat); //right */ movePos = position; connect (mgr, SIGNAL(onHotSpot(int)), SLOT(slotHotSpot(int))); if (transparent) mgr->doMove(true, false, true); else { /* QList<KToolBarItem> ons; for (KToolBarItem *b = items.first(); b; b=items.next()) { if (b->isEnabled()) ons.append(b); b->setEnabled(false); } */ mgr->doMove(true, false, false); /* for (KToolBarItem *b = ons.first(); b; b=ons.next()) b->setEnabled(true); */ } if (transparent) { setBarPos (movePos); if (movePos == Floating) move (mgr->x(), mgr->y()); if (!isVisible()) show(); } mouseEntered = false; delete mgr; mgr=0; repaint (false); //debug ("KToolBar: moving done"); } }}void KToolBar::mouseReleaseEvent ( QMouseEvent * ){ if (mgr) mgr->stop(); if (toggleFlatOnRelease && position != Floating) setFlat (position != Flat);}void KToolBar::setFlat (bool flag){#define also if (flag && (position == Floating && position == Flat)) return; if (!flag && (position != Flat)) also return; if (flag) //flat { lastPosition = position; // test float. I did and it works by miracle!? //debug ("Flat"); position = Flat; horizontal = false; resize(30, 10); for (KToolBarItem *b = items.first(); b; b=items.next()) // Nasty hack: b->move(100,100); // move items out of sight enableFloating(false); emit moved(Flat); // KTM will block this->updateRects } else //unflat { //debug ("Unflat"); setBarPos(lastPosition); enableFloating(true); emit moved (position); // KTM will call this->updateRects }}/************************************************************************* * KRadioGroup * *************************************************************************/KRadioGroup::KRadioGroup (QWidget *_parent, const char *_name): QObject(_parent, _name){ buttons.setAutoDelete(false); tb = (KToolBar *)_parent; connect (tb, SIGNAL(toggled(int)), this, SLOT(slotToggled(int)));}void KRadioGroup::addButton (int id){ for (KToolBarItem *b = tb->items.first(); b; b=tb->items.next()) if (b->ID() == id ) { buttons.insert(id, (KToolBarButton *) b->getItem()); ((KToolBarButton *) b->getItem())->setRadio(true); }}void KRadioGroup::removeButton (int id){ buttons[id]->setRadio(false); buttons.remove(id);}void KRadioGroup::slotToggled(int id){ if (buttons[id] && buttons[id]->isOn()) { QIntDictIterator<KToolBarButton> it(buttons); while (it.current()) { if (it.currentKey() != id) it.current()->on(false); ++it; } }}#include "ktoolbar.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -