void TPanelTitleBar::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = this->rect(); QColor titleColor; QColor brushColor; TPanel *dw = qobject_cast<TPanel *>(parentWidget()); Q_ASSERT(dw != 0); if (!dw->isFloating()) { if (dw->widgetInThisPanelIsFocused()) { brushColor = QColor(64, 64, 64); titleColor = QColor(Qt::white); } else { brushColor = QColor(100, 100, 100); titleColor = QColor(192, 192, 192); } } else if (isActiveWindow()) { brushColor = QColor(96, 96, 96); titleColor = QColor(Qt::white); } else { brushColor = QColor(128, 128, 128); titleColor = QColor(192, 192, 192); } painter.setBrush(brushColor); painter.setPen(Qt::black); painter.drawRect(rect.adjusted(0, 0, -1, -1)); painter.setPen(titleColor); painter.drawLine(rect.topLeft(), rect.bottomLeft()); painter.drawLine(rect.topLeft(), rect.topRight()); if (dw->getOrientation() == TDockWidget::vertical) { QString titleText = painter.fontMetrics().elidedText( dw->windowTitle(), Qt::ElideRight, rect.width() - 50); painter.setBrush(Qt::NoBrush); painter.setPen(titleColor); painter.drawText(QPointF(10, 15), titleText); } if (dw->isFloating()) { const static QPixmap closeButtonPixmap(":/Resources/close_pane.png"); const static QPixmap closeButtonPixmapOver(":/Resources/close_pane_rollover.png"); QRect closeRect(rect.right() - 17, rect.top() + 1, 16, 16); if (m_closeButtonHighlighted) painter.drawPixmap(closeRect, closeButtonPixmapOver); else painter.drawPixmap(closeRect, closeButtonPixmap); } painter.end(); }
void TPanelTitleBar::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = this->rect(); bool isPanelActive; TPanel *dw = qobject_cast<TPanel *>(parentWidget()); Q_ASSERT(dw != 0); // docked panel if (!dw->isFloating()) { isPanelActive = dw->widgetInThisPanelIsFocused(); qDrawBorderPixmap(&painter, rect, QMargins(3, 3, 3, 3), (isPanelActive) ? m_activeBorderPm : m_borderPm); } // floating panel else { isPanelActive = isActiveWindow(); qDrawBorderPixmap( &painter, rect, QMargins(3, 3, 3, 3), (isPanelActive) ? m_floatActiveBorderPm : m_floatBorderPm); } if (dw->getOrientation() == TDockWidget::vertical) { QString titleText = painter.fontMetrics().elidedText( dw->windowTitle(), Qt::ElideRight, rect.width() - 50); painter.setBrush(Qt::NoBrush); painter.setPen(isPanelActive ? m_activeTitleColor : m_titleColor); painter.drawText(QPointF(10, 15), titleText); } if (dw->isFloating()) { const static QPixmap closeButtonPixmap( svgToPixmap(":/Resources/pane_close.svg", QSize(18, 18))); const static QPixmap closeButtonPixmapOver( svgToPixmap(":/Resources/pane_close_rollover.svg", QSize(18, 18))); QPoint closeButtonPos(rect.right() - 18, rect.top() + 1); if (m_closeButtonHighlighted) painter.drawPixmap(closeButtonPos, closeButtonPixmapOver); else painter.drawPixmap(closeButtonPos, closeButtonPixmap); } painter.end(); }