[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-26 19:38:34
Message-ID: 1169840314.929725.9029.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 627486 by ppenz:
Further optimizations for the status bar: hide the space information if the status \
bar text does not fit into the remaining width.
M +32 -12 dolphinstatusbar.cpp
M +13 -2 dolphinstatusbar.h
M +16 -7 statusbarmessagelabel.cpp
M +19 -4 statusbarmessagelabel.h
M +2 -6 statusbarspaceinfo.cpp
M +1 -1 statusbarspaceinfo.h
--- trunk/playground/utils/dolphin/src/dolphinstatusbar.cpp #627485:627486
@@ -57,7 +57,7 @@
m_messageLabel->setMinimumTextHeight(size.height());
connect(parent, SIGNAL(urlChanged(const KUrl&)),
- this, SLOT(updateSpaceInfo(const KUrl&)));
+ this, SLOT(updateSpaceInfoContent(const KUrl&)));
}
@@ -71,16 +71,12 @@
m_messageLabel->setText(msg);
m_messageLabel->setType(type);
- if (type == Error) {
- // assure that enough space is available for the error message and
- // hide the space information and progress information
- m_spaceInfo->hide();
+ const int widthGap = m_messageLabel->widthGap();
+ if (widthGap > 0) {
m_progressBar->hide();
m_progressText->hide();
}
- else if (!m_progressBar->isVisible()) {
- m_spaceInfo->show();
- }
+ showSpaceInfo();
}
DolphinStatusBar::Type DolphinStatusBar::type() const
@@ -145,6 +141,12 @@
m_defaultText = text;
}
+void DolphinStatusBar::resizeEvent(QResizeEvent* event)
+{
+ QWidget::resizeEvent(event);
+ QTimer::singleShot(0, this, SLOT(showSpaceInfo()));
+}
+
void DolphinStatusBar::updateProgressInfo()
{
const bool isErrorShown = (m_messageLabel->type() == Error);
@@ -160,15 +162,33 @@
// hide the progress information and show the space information
m_progressText->hide();
m_progressBar->hide();
- if (m_messageLabel->type() != Error) {
- m_spaceInfo->show();
- }
+ showSpaceInfo();
}
}
-void DolphinStatusBar::updateSpaceInfo(const KUrl& url)
+void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url)
{
m_spaceInfo->setUrl(url);
+ showSpaceInfo();
}
+void DolphinStatusBar::showSpaceInfo()
+{
+ const int widthGap = m_messageLabel->widthGap();
+ const bool isProgressBarVisible = m_progressBar->isVisible();
+
+ if (m_spaceInfo->isVisible()) {
+ // The space information is shown currently. Hide it
+ // if the progress bar is visible or if the status bar
+ // text does not fit into the available width.
+ const QSize size(m_progressBar->sizeHint());
+ if (isProgressBarVisible || (widthGap > 0)) {
+ m_spaceInfo->hide();
+ }
+ }
+ else if (widthGap + m_spaceInfo->width() <= 0) {
+ m_spaceInfo->show();
+ }
+}
+
#include "dolphinstatusbar.moc"
--- trunk/playground/utils/dolphin/src/dolphinstatusbar.h #627485:627486
@@ -110,16 +110,27 @@
void setDefaultText(const QString& text);
const QString& defaultText() const { return m_defaultText; }
+protected:
+ /** @see QWidget::resizeEvent() */
+ virtual void resizeEvent(QResizeEvent* event);
+
private slots:
void updateProgressInfo();
/**
* Is invoked, when the URL of the DolphinView, where the
* statusbar belongs too, has been changed. The space information
- * is updated.
+ * content is updated.
*/
- void updateSpaceInfo(const KUrl& url);
+ void updateSpaceInfoContent(const KUrl& url);
+ /**
+ * Shows the space information if there is enough room to show it
+ * without the need to clip the status bar text. If the progress
+ * bar is shown, the space information won't be shown.
+ */
+ void showSpaceInfo();
+
private:
StatusBarMessageLabel* m_messageLabel;
StatusBarSpaceInfo* m_spaceInfo;
--- trunk/playground/utils/dolphin/src/statusbarmessagelabel.cpp #627485:627486
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "statusbarmessagelabel.h"
@@ -106,6 +106,13 @@
}
}
+int StatusBarMessageLabel::widthGap() const
+{
+ QFontMetrics fontMetrics(font());
+ const int defaultGap = 10;
+ return fontMetrics.width(m_text) - availableTextWidth() + defaultGap;
+}
+
void StatusBarMessageLabel::paintEvent(QPaintEvent* /* event */)
{
QPainter painter(this);
@@ -189,13 +196,10 @@
return;
}
-
- int availableWidth = width() - m_pixmap.width() - pixmapGap() * 2;
-
QFontMetrics fontMetrics(font());
- QRect bounds(fontMetrics.boundingRect(0, 0, availableWidth, height(),
- Qt::AlignVCenter | Qt::TextWordWrap,
- m_text));
+ const QRect bounds(fontMetrics.boundingRect(0, 0, availableTextWidth(), \
height(), + Qt::AlignVCenter | \
Qt::TextWordWrap, + m_text));
int requiredHeight = bounds.height();
if (requiredHeight < m_minTextHeight) {
requiredHeight = m_minTextHeight;
@@ -204,6 +208,11 @@
updateGeometry();
}
+int StatusBarMessageLabel::availableTextWidth() const
+{
+ return width() - m_pixmap.width() - pixmapGap() * 2;
+}
+
QColor StatusBarMessageLabel::mixColors(const QColor& c1,
const QColor& c2,
int percent) const
--- trunk/playground/utils/dolphin/src/statusbarmessagelabel.h #627485:627486
@@ -37,8 +37,6 @@
* is shown in front of the text. For message texts having the type
* DolphinStatusBar::Error a dynamic color blending is done to get the
* attention from the user.
- *
- * @author Peter Penz
*/
class StatusBarMessageLabel : public QWidget
{
@@ -58,17 +56,34 @@
void setMinimumTextHeight(int min);
int minimumTextHeight() const { return m_minTextHeight; }
+ /**
+ * Returns the gap of the width of the current set text to the
+ * width of the message label. A gap <= 0 means that the text
+ * fits into the available width.
+ */
+ int widthGap() const;
+
protected:
- /** @see QWidget::paintEvent */
+ /** @see QWidget::paintEvent() */
virtual void paintEvent(QPaintEvent* event);
- /** @see QWidget::resizeEvent */
+ /** @see QWidget::resizeEvent() */
virtual void resizeEvent(QResizeEvent* event);
private slots:
void timerDone();
+
+ /**
+ * Increases the height of the message label so that
+ * the given text fits into given area.
+ */
void assureVisibleText();
+ /**
+ * Returns the available width in pixels for the text.
+ */
+ int availableTextWidth() const;
+
private:
enum State {
Default,
--- trunk/playground/utils/dolphin/src/statusbarspaceinfo.cpp #627485:627486
@@ -132,13 +132,9 @@
update();
}
-void StatusBarSpaceInfo::slotDone()
+void StatusBarSpaceInfo::showResult()
{
m_gettingSize = false;
- if ((m_kBSize > 0) && (m_kBAvailable > 0)) {
- show();
- }
-
update();
}
@@ -160,7 +156,7 @@
const unsigned long&,
const QString& )));
connect(job, SIGNAL(done()),
- this, SLOT(slotDone()));
+ this, SLOT(showResult()));
job->readDF(mountPoint);
}
--- trunk/playground/utils/dolphin/src/statusbarspaceinfo.h #627485:627486
@@ -58,7 +58,7 @@
const unsigned long& kBUsed,
const unsigned long& kBAvailable,
const QString& mountPoint);
- void slotDone();
+ void showResult();
/** Refreshs the space information for the current set Url. */
void refresh();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic