void NextClient::init() { createMainWidget(WResizeNoErase | WStaticContents); widget()->installEventFilter(this); widget()->setBackgroundMode( NoBackground ); QVBoxLayout *mainLayout = new QVBoxLayout(widget()); QBoxLayout *titleLayout = new QBoxLayout(0, QBoxLayout::LeftToRight, 0, 0, 0); QHBoxLayout *windowLayout = new QHBoxLayout(); mainLayout->addLayout(titleLayout); mainLayout->addLayout(windowLayout, 1); mainLayout->addSpacing(mustDrawHandle() ? handleSize : 1); windowLayout->addSpacing(1); if (isPreview()) windowLayout->addWidget(new QLabel(i18n( "<center><b>KStep preview</b></center>"), widget())); else windowLayout->addItem(new QSpacerItem( 0, 0 )); windowLayout->addSpacing(1); initializeButtonsAndTitlebar(titleLayout); }
bool NextClient::drawbound(const QRect& geom, bool /* clear */) { QPainter p(workspaceWidget()); p.setPen(QPen(Qt::white, 3)); p.setRasterOp(Qt::XorROP); p.drawRect(geom); int leftMargin = geom.left() + 2; p.fillRect(leftMargin, geom.top() + titleHeight - 1, geom.width() - 4, 3, Qt::white); if (mustDrawHandle()) { p.fillRect(leftMargin, geom.bottom() - handleSize - 1, geom.width() - 4, 3, Qt::white); } return true; }
int LaptopClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const { switch (lm) { case LM_TitleEdgeLeft: case LM_TitleEdgeRight: case LM_BorderLeft: case LM_BorderRight: return 4; case LM_BorderBottom: return mustDrawHandle() ? handleSize : 4; case LM_TitleEdgeTop: return 3; case LM_TitleEdgeBottom: return 1; case LM_TitleBorderLeft: case LM_TitleBorderRight: return 0; case LM_ButtonWidth: { if (btn && (btn->type()==HelpButton||btn->type()==OnAllDesktopsButton) ) { return btnWidth1; } else { return btnWidth2; } } case LM_ButtonHeight: case LM_TitleHeight: if (isToolWindow() ) return titleHeight-2; else return titleHeight; case LM_ButtonSpacing: return 0; default: return KCommonDecoration::layoutMetric(lm, respectWindowState, btn); } }
void NextClient::borders(int &left, int &right, int &top, int &bottom) const { left = right = 1; top = titleHeight; // FRAME is this ok? bottom = mustDrawHandle() ? handleSize : 1; }
void NextClient::paintEvent( QPaintEvent* ) { QPainter p(widget()); // Draw black frame QRect fr = widget()->rect(); p.setPen(Qt::black); p.drawRect(fr); // Draw title bar QRect t = titlebar->geometry(); t.setTop(1); p.drawTiledPixmap(t.x()+1, t.y()+1, t.width()-2, t.height()-2, isActive() ? *aTitlePix : *iTitlePix); qDrawShadePanel(&p, t.x(), t.y(), t.width(), t.height()-1, options()->colorGroup(KDecoration::ColorTitleBar, isActive())); p.drawLine(t.x(), t.bottom(), t.right(), t.bottom()); #if 0 // Why setting up a clipping region if it is not used? (setClipping(false)) QRegion r = fr; r = r.subtract( t ); p.setClipRegion( r ); p.setClipping(false); #endif t.setTop( 1 ); t.setHeight(t.height()-2); t.setLeft( t.left() + 4 ); t.setRight( t.right() - 2 ); p.setPen(options()->color(KDecoration::ColorFont, isActive())); p.setFont(options()->font(isActive())); p.drawText( t, AlignCenter | AlignVCenter, caption() ); // Draw resize handle if (mustDrawHandle()) { int corner = 16 + 3*handleSize/2; qDrawShadePanel(&p, fr.x() + 1, fr.bottom() - handleSize, corner-1, handleSize, options()->colorGroup(KDecoration::ColorHandle, isActive()), false); p.drawTiledPixmap(fr.x() + 2, fr.bottom() - handleSize + 1, corner - 3, handleSize - 2, isActive() ? *aHandlePix : *iHandlePix); qDrawShadePanel(&p, fr.x() + corner, fr.bottom() - handleSize, fr.width() - 2*corner, handleSize, options()->colorGroup(KDecoration::ColorFrame, isActive()), false); p.drawTiledPixmap(fr.x() + corner + 1, fr.bottom() - handleSize + 1, fr.width() - 2*corner - 2, handleSize - 2, isActive() ? *aFramePix : *iFramePix); qDrawShadePanel(&p, fr.right() - corner + 1, fr.bottom() - handleSize, corner - 1, handleSize, options()->colorGroup(KDecoration::ColorHandle, isActive()), false); p.drawTiledPixmap(fr.right() - corner + 2, fr.bottom() - handleSize + 1, corner - 3, handleSize - 2, isActive() ? *aHandlePix : *iHandlePix); } }
/** Adds the buttons for one side of the title bar, based on the spec * string; see the KWinInternal::KDecoration class, methods * titleButtonsLeft and titleBUttonsRight. */ void NextClient::addButtons(QBoxLayout* titleLayout, const QString& spec) { for (unsigned int i=0; i<spec.length(); i++) { switch (spec[i].latin1()) { case 'A': if (isMaximizable()) { button[MAXIMIZE_IDX] = new NextButton(this, "maximize", maximize_bits, 10, 10, i18n("Maximize"), LeftButton|MidButton|RightButton); titleLayout->addWidget( button[MAXIMIZE_IDX] ); connect( button[MAXIMIZE_IDX], SIGNAL(clicked()), this, SLOT(maximizeButtonClicked()) ); } break; case 'H': if (providesContextHelp()) { button[HELP_IDX] = new NextButton(this, "help", question_bits, 10, 10, i18n("Help")); titleLayout->addWidget( button[HELP_IDX] ); connect( button[HELP_IDX], SIGNAL(clicked()), this, SLOT(showContextHelp()) ); } break; case 'I': if (isMinimizable()) { button[ICONIFY_IDX] = new NextButton(this, "iconify", iconify_bits, 10, 10, i18n("Minimize")); titleLayout->addWidget( button[ICONIFY_IDX] ); connect( button[ICONIFY_IDX], SIGNAL(clicked()), this, SLOT(minimize()) ); } break; case 'M': button[MENU_IDX] = new NextButton(this, "menu", NULL, 10, 10, i18n("Menu"), LeftButton|RightButton); titleLayout->addWidget( button[MENU_IDX] ); // NOTE DIFFERENCE: capture pressed(), not clicked() connect( button[MENU_IDX], SIGNAL(pressed()), this, SLOT(menuButtonPressed()) ); break; case 'L': button[SHADE_IDX] = new NextButton(this, "shade", NULL, 0, 0, i18n("Shade")); titleLayout->addWidget( button[SHADE_IDX] ); connect( button[SHADE_IDX], SIGNAL(clicked()), this, SLOT(shadeClicked()) ); // NOTE DIFFERENCE: set the pixmap separately (2 states) shadeChange(); break; case 'S': button[STICKY_IDX] = new NextButton(this, "sticky", NULL, 0, 0, i18n("On all desktops")); titleLayout->addWidget( button[STICKY_IDX] ); connect( button[STICKY_IDX], SIGNAL(clicked()), this, SLOT(toggleOnAllDesktops()) ); // NOTE DIFFERENCE: set the pixmap separately (2 states) desktopChange(); break; case 'F': button[ABOVE_IDX] = new NextButton(this, "above", NULL, 0, 0, ""); titleLayout->addWidget( button[ABOVE_IDX] ); connect( button[ABOVE_IDX], SIGNAL(clicked()), this, SLOT(aboveClicked()) ); connect(this, SIGNAL(keepAboveChanged(bool)), SLOT(keepAboveChange(bool))); keepAboveChange(keepAbove()); break; case 'B': button[BELOW_IDX] = new NextButton(this, "below", NULL, 0, 0, ""); titleLayout->addWidget( button[BELOW_IDX] ); connect( button[BELOW_IDX], SIGNAL(clicked()), this, SLOT(belowClicked()) ); connect(this, SIGNAL(keepBelowChanged(bool)), SLOT(keepBelowChange(bool))); keepBelowChange(keepBelow()); break; case 'X': if (isCloseable()) { button[CLOSE_IDX] = new NextButton(this, "close", close_bits, 10, 10, i18n("Close")); titleLayout->addWidget(button[CLOSE_IDX]); connect(button[CLOSE_IDX], SIGNAL(clicked()), this, SLOT(closeWindow())); } break; case 'R': if (mustDrawHandle()) { button[RESIZE_IDX] = new NextButton(this, "resize", resize_bits, 10, 10, i18n("Resize")); titleLayout->addWidget(button[RESIZE_IDX]); // NOTE DIFFERENCE: capture pressed(), not clicked() connect(button[RESIZE_IDX], SIGNAL(pressed()), this, SLOT(resizePressed())); } break; case '_': // TODO: Add spacer handling break; default: kdDebug() << " Can't happen: unknown button code " << QString(spec[i]); break; } } }
void LaptopClient::paintEvent( QPaintEvent* ) { QPainter p(widget()); QPalette g = options()->palette(KDecoration::ColorFrame, isActive()); g.setCurrentColorGroup( QPalette::Active ); QRect r(widget()->rect()); p.setPen(Qt::black); p.drawRect(r.adjusted(0, 0, -1, -1)); // fill mid frame... p.setPen(g.background().color()); p.drawLine(r.x()+2, r.y()+2, r.right()-2, r.y()+2); p.drawLine(r.left()+2, r.y()+3, r.left()+2, r.bottom()-layoutMetric(LM_BorderBottom)+1); p.drawLine(r.right()-2, r.y()+3, r.right()-2, r.bottom()-layoutMetric(LM_BorderBottom)+1); p.drawLine(r.left()+3, r.y()+3, r.left()+3, r.y()+layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeTop) ); p.drawLine(r.right()-3, r.y()+3, r.right()-3, r.y()+layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeTop) ); if (!mustDrawHandle() ) p.drawLine(r.left()+1, r.bottom()-2, r.right()-1, r.bottom()-2); // outer frame p.setPen(g.color(QPalette::Light)); p.drawLine(r.x()+1, r.y()+1, r.right()-1, r.y()+1); p.drawLine(r.x()+1, r.y()+1, r.x()+1, r.bottom()-1); p.setPen(g.dark().color()); p.drawLine(r.right()-1, r.y()+1, r.right()-1, r.bottom()-1); p.drawLine(r.x()+1, r.bottom()-1, r.right()-1, r.bottom()-1); int th = titleHeight; int bb = handleSize + 2; // Bottom border int bs = handleSize - 2; // inner size of bottom border if (!mustDrawHandle()) { bb = 6; bs = 0; } if ( isToolWindow() ) th -= 2; // inner rect p.drawRect(r.x() + 3, r.y() + th + 3, r.width() - 7, r.height() - th - bb - 1); // handles if (mustDrawHandle()) { if (r.width() > 3*handleSize + 20) { int range = 8 + 3*handleSize/2; qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, range, handleSize - 2, g, false, 1, &g.brush(QPalette::Mid)); qDrawShadePanel(&p, r.x() + range + 1, r.bottom() - bs, r.width() - 2*range - 2, handleSize - 2, g, false, 1, isActive() ? &g.brush(QPalette::Background) : &g.brush(QPalette::Mid)); qDrawShadePanel(&p, r.right() - range, r.bottom() - bs, range, bs, g, false, 1, &g.brush(QPalette::Mid)); } else { qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, r.width() - 2, bs, g, false, 1, isActive() ? &g.brush(QPalette::Background) : &g.brush(QPalette::Mid)); } } r = titleRect(); if(isActive()){ updateActiveBuffer(); p.drawPixmap(r.x(), r.y(), activeBuffer); p.setPen(g.background().color()); p.drawPoint(r.x(), r.y()); p.drawPoint(r.right(), r.y()); p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom()); } else{ if(iUpperGradient) p.drawTiledPixmap(r.x(), r.y(), r.width(), r.height()-1, *iUpperGradient); else p.fillRect(r.x(), r.y(), r.width(), r.height()-1, options()->color(KDecoration::ColorTitleBar, false)); p.setFont(options()->font(false, isToolWindow() )); QFontMetrics fm(options()->font(false)); g = options()->palette(KDecoration::ColorTitleBar, false); g.setCurrentColorGroup( QPalette::Active ); if(iUpperGradient) p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4, r.y(), fm.width(caption())+8, r.height()-1, *iUpperGradient); else p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, r.y(), fm.width(caption())+8, r.height()-1, g.brush(QPalette::Background)); p.setPen(g.mid().color()); p.drawLine(r.x(), r.y(), r.right(), r.y()); p.drawLine(r.x(), r.y(), r.x(), r.bottom()); p.setPen(g.color(QPalette::Button)); p.drawLine(r.right(), r.y(), r.right(), r.bottom()); p.drawLine(r.x(), r.bottom(), r.right(), r.bottom()); p.setPen(options()->color(KDecoration::ColorFont, false)); p.drawText(r.x(), r.y()+1, r.width(), r.height()-1, Qt::AlignCenter, caption() ); g = options()->palette(KDecoration::ColorFrame, true); g.setCurrentColorGroup( QPalette::Active ); p.setPen(g.background().color()); p.drawPoint(r.x(), r.y()); p.drawPoint(r.right(), r.y()); p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom()); } }