Skip to content

Commit

Permalink
Modify the method of drawing the window box border
Browse files Browse the repository at this point in the history
* White lines appear at rounded corners when drawing translucent
  borders using QSS
* The current use of self-painted border lines
  • Loading branch information
droiing committed May 6, 2020
1 parent 7ada542 commit 070540f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/ukws_window_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ UkwsWindowBox::UkwsWindowBox(QWidget *parent) : QWidget(parent)
frameXid = 0;
hasFrame = false;
drag = nullptr;
isSelected = false;
titleAutoHide = false;

titleLabel = new UkwsWindowExtraLabel();
Expand Down Expand Up @@ -162,6 +163,27 @@ void UkwsWindowBox::paintEvent(QPaintEvent *event)
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &styleOpt, &painter, this);

if (isSelected) {
QSize size = this->size();

// 获取圆角边框区域
QRectF rect;
QPainterPath path;

rect = QRectF(UKWS_WINDOWBOX_BORDER, UKWS_WINDOWBOX_BORDER,
size.width() - UKWS_WINDOWBOX_BORDER * 2,
size.height() - UKWS_WINDOWBOX_BORDER * 2);
path.addRoundedRect(rect, UKWS_THUMBNAIL_RADIUS, UKWS_THUMBNAIL_RADIUS);
rect = QRectF(0, 0, size.width(), size.height());
path.addRoundedRect(rect, UKWS_THUMBNAIL_RADIUS + UKWS_WINDOWBOX_BORDER,
UKWS_THUMBNAIL_RADIUS + UKWS_WINDOWBOX_BORDER);

painter.setRenderHint(QPainter::Antialiasing, false);
painter.setBrush(QBrush(QColor(255, 255, 255, 128)));
painter.setPen(QPen(QColor(255, 255, 255, 0)));
painter.drawPath(path);
}

QWidget::paintEvent(event);
}

Expand Down Expand Up @@ -456,16 +478,14 @@ void UkwsWindowBox::setThumbnailNormal()

void UkwsWindowBox::setWindowBoxSelected()
{
this->setStyleSheet("QWidget#winbox{padding:0px;"
"border:4px solid rgb(255, 255, 255, 127);"
"border-radius: 6px;}");
isSelected = true;
update();
}

void UkwsWindowBox::setWindowBoxUnselected()
{
this->setStyleSheet("QWidget#winbox{padding:0px;"
"border:4px solid rgb(255, 255, 255, 0);"
"border-radius: 6px;}");
isSelected = false;
update();
}

void UkwsWindowBox::setTitleAutoHide(bool autoHide)
Expand Down
2 changes: 2 additions & 0 deletions src/ukws_window_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public slots:
WnckWindow *wnckWin;
bool hasFrame;

bool isSelected;

QDrag *drag;
QSize dragIconSize;
QTimer scaleTimer;
Expand Down

0 comments on commit 070540f

Please sign in to comment.