127 lines
3.4 KiB
C++
127 lines
3.4 KiB
C++
#include "totalTitleBar.h"
|
|
|
|
TotalTitleBar::TotalTitleBar(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
minPix = style()->standardPixmap(QStyle::SP_TitleBarMinButton);
|
|
closePix = style()->standardPixmap(QStyle::SP_TitleBarCloseButton);
|
|
floatPix = style()->standardPixmap(QStyle::SP_TitleBarNormalButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize TotalTitleBar::minimumSizeHint() const
|
|
{
|
|
QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
|
|
|
|
Q_ASSERT(dw != 0);
|
|
|
|
QSize result(100, 45);
|
|
|
|
if(dw->features() & QDockWidget::DockWidgetVerticalTitleBar)
|
|
result.transpose();
|
|
|
|
return result;
|
|
}
|
|
|
|
void TotalTitleBar::paintEvent(QPaintEvent*)
|
|
{
|
|
QPainter painter(this);
|
|
QRect rect = this->rect();
|
|
QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
|
|
Q_ASSERT(dw != 0);
|
|
|
|
if(dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
|
|
QSize s = rect.size();
|
|
s.transpose();
|
|
rect.setSize(s);
|
|
|
|
painter.translate(rect.left(), rect.top() + rect.width());
|
|
painter.rotate(-90);
|
|
painter.translate(-rect.left(), -rect.top());
|
|
|
|
}
|
|
painter.fillRect(rect.left()+2, rect.top()+4, rect.width()-3, rect.height()-4, backgroudColor); //QColor(67, 67, 67, 100)
|
|
//painter.drawPixmap(rect.topRight() - QPoint(closePix.width() + 10, -10), closePix);
|
|
//painter.drawPixmap(rect.topRight() - QPoint(minPix.width() + 10 + closePix.width() + 10, -7), minPix);
|
|
//painter.drawPixmap(rect.topRight() - QPoint(floatPix.width() + 10 + minPix.width() + 10 + closePix.width() + 10, -10), floatPix);
|
|
|
|
QFont font1("微软雅黑", fontSize, false, false); //fontSize 10
|
|
painter.setFont(font1);
|
|
painter.setPen(fontColor); // fontColor QColor(220, 220, 220)
|
|
painter.drawText(rect.left() + 10, 20+12, titleBarText); // titleBarText QStringLiteral("动画")
|
|
}
|
|
|
|
void TotalTitleBar::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event);
|
|
return;
|
|
|
|
//暂时不处理
|
|
////////////////////////////////
|
|
/*QPoint pos = event->pos();
|
|
QRect rect = this->rect();
|
|
QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
|
|
Q_ASSERT(dw != 0);
|
|
if(dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
|
|
|
|
QPoint p = pos;
|
|
pos.setX(rect.left() + rect.bottom() - p.y());
|
|
pos.setY(rect.top() + p.x() - rect.left());
|
|
|
|
QSize s = rect.size();
|
|
s.transpose();
|
|
rect.setSize(s);
|
|
|
|
}
|
|
const int buttonRight = 10;
|
|
const int buttonWidth = 20;
|
|
int right = rect.right() - pos.x();
|
|
int button = (right - buttonRight) / buttonWidth;
|
|
|
|
qDebug() << rect.right() << " --- " << pos.x() << " --- " << right << " --- " << button;
|
|
|
|
switch(button) {
|
|
case 0:
|
|
event->accept();
|
|
dw->hide();
|
|
break;
|
|
|
|
case 1:
|
|
event->accept();
|
|
dw->setFloating(!dw->isFloating());
|
|
break;
|
|
|
|
case 2: {
|
|
event->accept();
|
|
QDockWidget::DockWidgetFeatures features = dw->features();
|
|
if(features & QDockWidget::DockWidgetVerticalTitleBar)
|
|
features &= ~QDockWidget::DockWidgetVerticalTitleBar;
|
|
else
|
|
features |= QDockWidget::DockWidgetVerticalTitleBar;
|
|
|
|
dw->setFeatures(features);
|
|
break;
|
|
|
|
}
|
|
default:
|
|
event->ignore();
|
|
break;
|
|
}*/
|
|
|
|
}
|
|
|
|
void TotalTitleBar::setAttr(QColor _backgroudColor = QColor(67, 67, 67, 100), int _fontSize = 10, QString _titleBarText = QStringLiteral(""), QColor _fontColor = QColor(220, 220, 220))
|
|
{
|
|
backgroudColor = _backgroudColor;
|
|
fontSize = _fontSize; // 默认标题栏文本字号
|
|
titleBarText = _titleBarText; // 默认标题栏文本
|
|
fontColor = _fontColor; // 默认标题栏文本颜色
|
|
update();
|
|
}
|
|
|
|
void TotalTitleBar::updateMask()
|
|
{
|
|
}
|