Changeset View
Changeset View
Standalone View
Standalone View
src/progressBox.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 82 | { | |||
---|---|---|---|---|---|
84 | m_timer.stop(); | 84 | m_timer.stop(); | ||
85 | QTimer::singleShot(2000, this, &QWidget::hide); | 85 | QTimer::singleShot(2000, this, &QWidget::hide); | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | void | 88 | void | ||
89 | ProgressBox::setText(int files) | 89 | ProgressBox::setText(int files) | ||
90 | { | 90 | { | ||
91 | m_text = i18np("%1 File", "%1 Files", files); | 91 | m_text = i18np("%1 File", "%1 Files", files); | ||
92 | m_textWidth = fontMetrics().width(m_text); | 92 | m_textWidth = fontMetrics().horizontalAdvance(m_text); | ||
aacid: This increases the Qt dependency to 5.11, please change the CMakeLists.txt accordingly (or… | |||||
@aacid I updated dependency to Qt 5.11. According to the previous deprecation message from compiler, it suggests to use horizontalAdvance instead of boundingRect. I am not sure about the reason. But from the result, horizontalAdvance did the exact same thing as width function. guoyunhe: @aacid I updated dependency to Qt 5.11. According to the previous deprecation message from… | |||||
93 | m_textHeight = fontMetrics().height(); | 93 | m_textHeight = fontMetrics().height(); | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | #define PIECES_NUM 4 | 96 | #define PIECES_NUM 4 | ||
97 | static const float angleFactor[] = { -0.25, 0.9, -1.0, 0.3 }; | 97 | static const float angleFactor[] = { -0.25, 0.9, -1.0, 0.3 }; | ||
98 | static const float length[] = { 1.0, 1.0, 1.0, 1.0 }; | 98 | static const float length[] = { 1.0, 1.0, 1.0, 1.0 }; | ||
99 | static const int aLength[] = { 2000, 2000, 2000, 2000 }; | 99 | static const int aLength[] = { 2000, 2000, 2000, 2000 }; | ||
100 | 100 | | |||
101 | void ProgressBox::paintEvent(QPaintEvent*) | 101 | void ProgressBox::paintEvent(QPaintEvent*) | ||
102 | { | 102 | { | ||
103 | 103 | | |||
104 | QPainter paint(this); | 104 | QPainter paint(this); | ||
105 | paint.setPen(Qt::transparent); | 105 | paint.setPen(Qt::transparent); | ||
106 | paint.setRenderHint(QPainter::Antialiasing); | 106 | paint.setRenderHint(QPainter::Antialiasing); | ||
107 | static int tick = 0; | 107 | static int tick = 0; | ||
108 | tick+=16; | 108 | tick+=16; | ||
109 | 109 | | |||
110 | for (int i=0; i<PIECES_NUM; i++) { | 110 | for (int i=0; i<PIECES_NUM; i++) { | ||
111 | const int size = qMin(width(), height()) * length[i]; | 111 | const qreal size = qMin(width(), height()) * length[i]; | ||
112 | const QRect rect(width() / 2 - size / 2, height() / 2 - size / 2, size, size); | 112 | const QRectF rect(width() / 2 - size / 2, height() / 2 - size / 2, size, size); | ||
113 | int angle = angleFactor[i] + tick*angleFactor[i]; | 113 | int angle = angleFactor[i] + tick*angleFactor[i]; | ||
114 | QRadialGradient gradient(rect.center(), sin(angle/160.0f) * 100); | 114 | QRadialGradient gradient(rect.center(), sin(angle/160.0f) * 100); | ||
115 | gradient.setColorAt(0, QColor::fromHsv(abs(angle/16) % 360 , 160, 255)); | 115 | gradient.setColorAt(0, QColor::fromHsv(abs(angle/16) % 360 , 160, 255)); | ||
116 | gradient.setColorAt(1, QColor::fromHsv(abs(angle/16) % 360 , 160, 128)); | 116 | gradient.setColorAt(1, QColor::fromHsv(abs(angle/16) % 360 , 160, 128)); | ||
117 | QBrush brush(gradient); | 117 | QBrush brush(gradient); | ||
118 | paint.setBrush(brush); | 118 | paint.setBrush(brush); | ||
119 | paint.drawPie(QRect(rect), angle, aLength[i]); | 119 | paint.drawPie(QRectF(rect), angle, aLength[i]); | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | paint.translate(0.5, 0.5); | 122 | paint.translate(0.5, 0.5); | ||
123 | QRectF textRect(width() / 2 - m_textWidth/2 - 5, width() / 2 - m_textHeight - 5, m_textWidth + 10, m_textHeight + 10); | 123 | QRectF textRect(width() / 2 - m_textWidth/2 - 5, width() / 2 - m_textHeight - 5, m_textWidth + 10, m_textHeight + 10); | ||
124 | paint.fillRect(textRect, m_colorScheme.background(KColorScheme::ActiveBackground).color()); | 124 | paint.fillRect(textRect, m_colorScheme.background(KColorScheme::ActiveBackground).color()); | ||
125 | paint.translate(-0.5, -0.5); | 125 | paint.translate(-0.5, -0.5); | ||
126 | paint.setPen(m_colorScheme.foreground().color()); | 126 | paint.setPen(m_colorScheme.foreground().color()); | ||
127 | paint.drawText(textRect, Qt::AlignCenter, m_text); | 127 | paint.drawText(textRect, Qt::AlignCenter, m_text); | ||
128 | } | 128 | } | ||
129 | 129 | | |||
130 | 130 | | |||
131 | 131 | |
This increases the Qt dependency to 5.11, please change the CMakeLists.txt accordingly (or maybe try to use bondingRect and see if that works since that doesn't need a newer Qt than we need at tis point)