[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/utils/dolphin/src
From: Peter Penz <peter.penz () gmx ! at>
Date: 2007-01-31 22:03:42
Message-ID: 1170281022.130686.7578.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 628905 by ppenz:
Queue error messages so that a currently shown error message is not replaced until \
the user confirmed the reading. If there are no pending error messages and a timeout \
has been exceeded, the currently shown error messages automatically fades out as soon \
as the user triggered another action. This behavior should correspond to Ellens \
suggestions (I hope :-)).
M +11 -8 dolphinstatusbar.cpp
M +1 -3 dolphinstatusbar.h
M +79 -49 statusbarmessagelabel.cpp
M +29 -4 statusbarmessagelabel.h
M +3 -3 statusbarspaceinfo.cpp
M +1 -1 statusbarspaceinfo.h
--- trunk/playground/utils/dolphin/src/dolphinstatusbar.cpp #628904:628905
@@ -71,8 +71,7 @@
void DolphinStatusBar::setMessage(const QString& msg,
Type type)
{
- m_messageLabel->setText(msg);
- m_messageLabel->setType(type);
+ m_messageLabel->setMessage(msg, type);
const int widthGap = m_messageLabel->widthGap();
if (widthGap > 0) {
@@ -123,27 +122,31 @@
QTimer::singleShot(500, this, SLOT(updateProgressInfo()));
}
+ const QString& defaultText = m_messageLabel->defaultText();
const QString msg(m_messageLabel->text());
if ((percent == 0) && !msg.isEmpty()) {
setMessage(QString::null, Default);
}
- else if ((percent == 100) && (msg != m_defaultText)) {
- setMessage(m_defaultText, Default);
+ else if ((percent == 100) && (msg != defaultText)) {
+ setMessage(defaultText, Default);
}
}
void DolphinStatusBar::clear()
{
- // TODO: check for timeout, so that it's prevented that
- // a message is cleared too early.
- setMessage(m_defaultText, Default);
+ setMessage(m_messageLabel->defaultText(), Default);
}
void DolphinStatusBar::setDefaultText(const QString& text)
{
- m_defaultText = text;
+ m_messageLabel->setDefaultText(text);
}
+const QString& DolphinStatusBar::defaultText() const
+{
+ return m_messageLabel->defaultText();
+}
+
void DolphinStatusBar::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
--- trunk/playground/utils/dolphin/src/dolphinstatusbar.h #628904:628905
@@ -108,7 +108,7 @@
* is cleared by DolphinStatusBar::clear().
*/
void setDefaultText(const QString& text);
- const QString& defaultText() const { return m_defaultText; }
+ const QString& defaultText() const;
protected:
/** @see QWidget::resizeEvent() */
@@ -138,8 +138,6 @@
QLabel* m_progressText;
QProgressBar* m_progressBar;
int m_progress;
-
- QString m_defaultText;
};
#endif
--- trunk/playground/utils/dolphin/src/statusbarmessagelabel.cpp #628904:628905
@@ -48,69 +48,73 @@
connect(m_timer, SIGNAL(timeout()),
this, SLOT(timerDone()));
- m_closeButton = new QPushButton(KIcon("close"), QString::null, this);
+ m_closeButton = new QPushButton(i18n("Close"), this);
m_closeButton->hide();
+ connect(m_closeButton, SIGNAL(clicked()),
+ this, SLOT(closeErrorMessage()));
}
StatusBarMessageLabel::~StatusBarMessageLabel()
{
}
-void StatusBarMessageLabel::setType(DolphinStatusBar::Type type)
+void StatusBarMessageLabel::setMessage(const QString& text,
+ DolphinStatusBar::Type type)
{
- if ((type != m_type) || (type == DolphinStatusBar::Error)) {
- m_type = type;
+ if (m_type == DolphinStatusBar::Error) {
+ // If an error is shown currently, other error messages get queued.
+ // Non-error messages are ignored if there are pending error messages.
+ if (type == DolphinStatusBar::Error) {
+ m_pendingMessages.append(text);
+ return;
+ }
+ if ((m_state != Default) || !m_pendingMessages.isEmpty()) {
+ return;
+ }
+ }
- m_timer->stop();
- m_illumination = 0;
- m_state = Default;
+ if ((text == m_text) && (type == m_type)) {
+ return;
+ }
- const char* iconName = 0;
- QPixmap pixmap;
- switch (type) {
- case DolphinStatusBar::OperationCompleted:
- iconName = "ok";
- m_closeButton->hide();
- break;
+ m_text = text;
+ m_type = type;
- case DolphinStatusBar::Information:
- iconName = "info";
- m_closeButton->hide();
- break;
+ m_timer->stop();
+ m_illumination = 0;
+ m_state = Default;
- case DolphinStatusBar::Error:
- iconName = "error";
- m_timer->start(100);
- m_state = Illuminate;
+ const char* iconName = 0;
+ QPixmap pixmap;
+ switch (type) {
+ case DolphinStatusBar::OperationCompleted:
+ iconName = "ok";
+ m_closeButton->hide();
+ break;
- updateCloseButtonPosition();
- m_closeButton->show();
- break;
+ case DolphinStatusBar::Information:
+ iconName = "info";
+ m_closeButton->hide();
+ break;
- case DolphinStatusBar::Default:
- default:
- m_closeButton->hide();
- break;
- }
+ case DolphinStatusBar::Error:
+ iconName = "error";
+ m_timer->start(100);
+ m_state = Illuminate;
- m_pixmap = (iconName == 0) ? QPixmap() : SmallIcon(iconName);
- QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
- update();
+ updateCloseButtonPosition();
+ m_closeButton->show();
+ break;
+
+ case DolphinStatusBar::Default:
+ default:
+ m_closeButton->hide();
+ break;
}
-}
-void StatusBarMessageLabel::setText(const QString& text)
-{
- if (text != m_text) {
- if (m_type == DolphinStatusBar::Error) {
- m_timer->start(100);
- m_illumination = 0;
- m_state = Illuminate;
- }
- m_text = text;
- QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
- update();
- }
+ m_pixmap = (iconName == 0) ? QPixmap() : SmallIcon(iconName);
+ QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
+ update();
}
void StatusBarMessageLabel::setMinimumTextHeight(int min)
@@ -118,6 +122,7 @@
if (min != m_minTextHeight) {
m_minTextHeight = min;
setMinimumHeight(min);
+ m_closeButton->setFixedHeight(min - borderGap() * 2);
}
}
@@ -165,6 +170,7 @@
void StatusBarMessageLabel::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
+ updateCloseButtonPosition();
QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText()));
}
@@ -256,7 +262,7 @@
{
const int buttonWidth = (m_type == DolphinStatusBar::Error) ?
m_closeButton->width() + borderGap() : 0;
- return width() - m_pixmap.width() - (borderGap() * 3) - buttonWidth;
+ return width() - m_pixmap.width() - (borderGap() * 4) - buttonWidth;
}
QColor StatusBarMessageLabel::mixColors(const QColor& c1,
@@ -272,9 +278,33 @@
void StatusBarMessageLabel::updateCloseButtonPosition()
{
- const int x = width() - m_closeButton->width();
- const int y = 2;
+ const int x = width() - m_closeButton->width() - borderGap();
+ const int y = height() - m_closeButton->height() - borderGap();
m_closeButton->move(x, y);
}
+void StatusBarMessageLabel::closeErrorMessage()
+{
+ if (!showPendingMessage()) {
+ reset();
+ setMessage(m_defaultText, DolphinStatusBar::Default);
+ }
+}
+
+bool StatusBarMessageLabel::showPendingMessage()
+{
+ if (!m_pendingMessages.isEmpty()) {
+ reset();
+ setMessage(m_pendingMessages.takeFirst(), DolphinStatusBar::Error);
+ return true;
+ }
+ return false;
+}
+
+void StatusBarMessageLabel::reset()
+{
+ m_text = QString::null;
+ m_type = DolphinStatusBar::Default;
+}
+
#include "statusbarmessagelabel.moc"
--- trunk/playground/utils/dolphin/src/statusbarmessagelabel.h #628904:628905
@@ -23,6 +23,7 @@
#include <dolphinstatusbar.h>
+#include <QList>
#include <QPixmap>
#include <QString>
#include <QWidget>
@@ -48,12 +49,14 @@
explicit StatusBarMessageLabel(QWidget* parent);
virtual ~StatusBarMessageLabel();
- void setType(DolphinStatusBar::Type type);
+ void setMessage(const QString& text, DolphinStatusBar::Type type);
+
DolphinStatusBar::Type type() const { return m_type; }
-
- void setText(const QString& text);
const QString& text() const { return m_text; }
+ void setDefaultText(const QString& text) { m_defaultText = text; }
+ const QString& defaultText() const { return m_defaultText; }
+
// TODO: maybe a better approach is possible with the size hint
void setMinimumTextHeight(int min);
int minimumTextHeight() const { return m_minTextHeight; }
@@ -92,7 +95,27 @@
*/
void updateCloseButtonPosition();
+ /**
+ * Closes the currently shown error message and replaces it
+ * by the next pending message.
+ */
+ void closeErrorMessage();
+
private:
+ /**
+ * Shows the next pending error message. If no pending message
+ * was in the queue, false is returned.
+ */
+ bool showPendingMessage();
+
+ /**
+ * Resets the message label properties. This is useful when the
+ * result of invoking StatusBarMessageLabel::setMessage() should
+ * not rely on previous states.
+ */
+ void reset();
+
+private:
enum State {
Default,
Illuminate,
@@ -108,6 +131,8 @@
int m_minTextHeight;
QTimer* m_timer;
QString m_text;
+ QString m_defaultText;
+ QList<QString> m_pendingMessages;
QPixmap m_pixmap;
QPushButton* m_closeButton;
@@ -115,7 +140,7 @@
const QColor& c2,
int percent) const;
- int borderGap() const { return 3; }
+ int borderGap() const { return 2; }
};
#endif
--- trunk/playground/utils/dolphin/src/statusbarspaceinfo.cpp #628904:628905
@@ -59,8 +59,8 @@
{
QPainter painter(this);
const int barWidth = width();
- const int barTop = 2;
- const int barHeight = height() - 4;
+ const int barTop = 1;
+ const int barHeight = height() - 5;
QString text;
@@ -98,7 +98,7 @@
text = i18n("Getting size...");
}
else {
- text = "";
+ text = QString::null;
QTimer::singleShot(0, this, SLOT(hide()));
}
}
--- trunk/playground/utils/dolphin/src/statusbarspaceinfo.h #628904:628905
@@ -60,7 +60,7 @@
const QString& mountPoint);
void showResult();
- /** Refreshs the space information for the current set Url. */
+ /** Refreshs the space information for the current set URL. */
void refresh();
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic