X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0dce0b3bef7a138a68ced9c3d5c61315ea4c83ef..664f97ff0d1c70f7df4f4fa32303949ee7a6e8fb:/src/statusbar/dolphinstatusbar.cpp diff --git a/src/statusbar/dolphinstatusbar.cpp b/src/statusbar/dolphinstatusbar.cpp index c733ebe02..a7585bed0 100644 --- a/src/statusbar/dolphinstatusbar.cpp +++ b/src/statusbar/dolphinstatusbar.cpp @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006-2012 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -21,180 +20,160 @@ #include "dolphinstatusbar.h" #include "dolphin_generalsettings.h" - -#include -#include -#include -#include -#include - #include "statusbarspaceinfo.h" +#include "views/dolphinview.h" +#include "views/zoomlevelinfo.h" + +#include +#include #include -#include #include -#include +#include +#include +#include #include -#include -#include +#include +#include #include +#include -#include -#include +namespace { + const int UpdateDelay = 50; +} -DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) : +DolphinStatusBar::DolphinStatusBar(QWidget* parent) : QWidget(parent), - m_view(view), - m_messageLabel(0), - m_spaceInfo(0), - m_zoomSlider(0), - m_progressBar(0), - m_stopButton(0), + m_text(), + m_defaultText(), + m_label(nullptr), + m_spaceInfo(nullptr), + m_zoomSlider(nullptr), + m_progressBar(nullptr), + m_stopButton(nullptr), m_progress(100), - m_showProgressBarTimer(0), - m_messageTimeStamp() + m_showProgressBarTimer(nullptr), + m_delayUpdateTimer(nullptr), + m_textTimestamp() { - connect(m_view, SIGNAL(urlChanged(KUrl)), - this, SLOT(updateSpaceInfoContent(KUrl))); - - // Initialize message label - m_messageLabel = new KonqStatusBarMessageLabel(this); + // Initialize text label + m_label = new KSqueezedTextLabel(m_text, this); + m_label->setWordWrap(true); + m_label->setTextFormat(Qt::PlainText); // Initialize zoom widget m_zoomSlider = new QSlider(Qt::Horizontal, this); - m_zoomSlider->setAccessibleName(i18n("Zoom slider")); + m_zoomSlider->setAccessibleName(i18n("Zoom")); + m_zoomSlider->setAccessibleDescription(i18nc("Description for zoom-slider (accessibility)", "Sets the size of the file icons.")); m_zoomSlider->setPageStep(1); + m_zoomSlider->setRange(ZoomLevelInfo::minimumLevel(), ZoomLevelInfo::maximumLevel()); - const int min = ZoomLevelInfo::minimumLevel(); - const int max = ZoomLevelInfo::maximumLevel(); - m_zoomSlider->setRange(min, max); - m_zoomSlider->setValue(view->zoomLevel()); - updateZoomSliderToolTip(view->zoomLevel()); - - connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setZoomLevel(int))); - connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(showZoomSliderToolTip(int))); - connect(m_view, SIGNAL(zoomLevelChanged(int,int)), this, SLOT(slotZoomLevelChanged(int,int))); - connect(m_view, SIGNAL(previewsShownChanged(bool)), this, SLOT(slotPreviewsShownChanged(bool))); + connect(m_zoomSlider, &QSlider::valueChanged, this, &DolphinStatusBar::zoomLevelChanged); + connect(m_zoomSlider, &QSlider::valueChanged, this, &DolphinStatusBar::updateZoomSliderToolTip); + connect(m_zoomSlider, &QSlider::sliderMoved, this, &DolphinStatusBar::showZoomSliderToolTip); // Initialize space information m_spaceInfo = new StatusBarSpaceInfo(this); - m_spaceInfo->setUrl(m_view->url()); // Initialize progress information m_stopButton = new QToolButton(this); - m_stopButton->setIcon(KIcon("process-stop")); + m_stopButton->setIcon(QIcon::fromTheme(QStringLiteral("process-stop"))); m_stopButton->setAccessibleName(i18n("Stop")); - // TODO: Add tooltip for KDE SC 4.7.0, if new strings are allowed again m_stopButton->setAutoRaise(true); + m_stopButton->setToolTip(i18nc("@tooltip", "Stop loading")); m_stopButton->hide(); - connect(m_stopButton, SIGNAL(clicked()), this, SIGNAL(stopPressed())); + connect(m_stopButton, &QToolButton::clicked, this, &DolphinStatusBar::stopPressed); - m_progressText = new QLabel(this); - m_progressText->hide(); + m_progressTextLabel = new QLabel(this); + m_progressTextLabel->hide(); m_progressBar = new QProgressBar(this); m_progressBar->hide(); m_showProgressBarTimer = new QTimer(this); - m_showProgressBarTimer->setInterval(1000); + m_showProgressBarTimer->setInterval(500); m_showProgressBarTimer->setSingleShot(true); - connect(m_showProgressBarTimer, SIGNAL(timeout()), this, SLOT(updateProgressInfo())); + connect(m_showProgressBarTimer, &QTimer::timeout, this, &DolphinStatusBar::updateProgressInfo); + + // initialize text updater delay timer + m_delayUpdateTimer = new QTimer(this); + m_delayUpdateTimer->setInterval(UpdateDelay); + m_delayUpdateTimer->setSingleShot(true); + connect(m_delayUpdateTimer, &QTimer::timeout, + this, &DolphinStatusBar::updateLabelText); // Initialize top layout and size policies - const int fontHeight = QFontMetrics(m_messageLabel->font()).height(); + const int fontHeight = QFontMetrics(m_label->font()).height(); const int zoomSliderHeight = m_zoomSlider->minimumSizeHint().height(); - const int contentHeight = qMax(fontHeight, zoomSliderHeight); + const int buttonHeight = m_stopButton->height(); + const int contentHeight = qMax(qMax(fontHeight, zoomSliderHeight), buttonHeight); + + QFontMetrics fontMetrics(m_label->font()); + + m_label->setFixedHeight(contentHeight); + m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - m_messageLabel->setMinimumTextHeight(contentHeight); + m_zoomSlider->setMaximumWidth(fontMetrics.averageCharWidth() * 25); - m_spaceInfo->setMaximumSize(200, contentHeight - 5); + m_spaceInfo->setFixedHeight(contentHeight); + m_spaceInfo->setMaximumWidth(fontMetrics.averageCharWidth() * 25); m_spaceInfo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - m_progressBar->setMaximumSize(200, contentHeight); - m_zoomSlider->setMaximumSize(150, contentHeight); - m_zoomSlider->setMinimumWidth(30); + m_progressBar->setFixedHeight(zoomSliderHeight); + m_progressBar->setMaximumWidth(fontMetrics.averageCharWidth() * 25); QHBoxLayout* topLayout = new QHBoxLayout(this); - topLayout->setMargin(0); + topLayout->setContentsMargins(2, 0, 2, 0); topLayout->setSpacing(4); - topLayout->addWidget(m_messageLabel); - topLayout->addWidget(m_zoomSlider); - topLayout->addWidget(m_spaceInfo); + topLayout->addWidget(m_label, 1); + topLayout->addWidget(m_zoomSlider, 1); + topLayout->addWidget(m_spaceInfo, 1); topLayout->addWidget(m_stopButton); - topLayout->addWidget(m_progressText); + topLayout->addWidget(m_progressTextLabel); topLayout->addWidget(m_progressBar); setExtensionsVisible(true); + setWhatsThis(xi18nc("@info:whatsthis Statusbar", "This is " + "the Statusbar. It contains three elements " + "by default (left to right):A text field" + " that displays the size of selected items. If only " + "one item is selected the name and type is shown as well." + "A zoom slider that allows you " + "to adjust the size of the icons in the view." + "Space information about the " + "current storage device.")); } DolphinStatusBar::~DolphinStatusBar() { } -void DolphinStatusBar::setMessage(const QString& msg, - Type type) +void DolphinStatusBar::setText(const QString& text) { - int timeout = 1000; // Timeout in milliseconds until default - // messages may overwrite other messages. - - QString message = msg; - if (message.isEmpty()) { - // Show the default text as fallback. An empty text indicates - // a clearing of the information message. - if (m_messageLabel->defaultText().isEmpty()) { - return; - } - message = m_messageLabel->defaultText(); - type = Default; - timeout = 0; - } - - KonqStatusBarMessageLabel::Type konqType = static_cast(type); - if ((message == m_messageLabel->text()) && (konqType == m_messageLabel->type())) { - // the message is already shown + if (m_text == text) { return; } - const QTime currentTime = QTime::currentTime(); - const bool skipMessage = (type == Default) && - m_messageTimeStamp.isValid() && - (m_messageTimeStamp.msecsTo(currentTime) < timeout); - if (skipMessage) { - // A non-default message is shown just for a very short time. Don't hide - // the message by a default message, so that the user gets the chance to - // read the information. - return; - } + m_textTimestamp = QTime::currentTime(); - m_messageLabel->setMessage(message, konqType); - if (type != Default) { - m_messageTimeStamp = currentTime; - } + m_text = text; + // will update status bar text in 50ms + m_delayUpdateTimer->start(); } -DolphinStatusBar::Type DolphinStatusBar::type() const +QString DolphinStatusBar::text() const { - return static_cast(m_messageLabel->type()); -} - -QString DolphinStatusBar::message() const -{ - return m_messageLabel->text(); + return m_text; } void DolphinStatusBar::setProgressText(const QString& text) { - m_progressText->setText(text); -} - -int DolphinStatusBar::progress() const -{ - return m_progress; + m_progressTextLabel->setText(text); } QString DolphinStatusBar::progressText() const { - return m_progressText->text(); + return m_progressTextLabel->text(); } void DolphinStatusBar::setProgress(int percent) @@ -202,20 +181,9 @@ void DolphinStatusBar::setProgress(int percent) // Show a busy indicator if a value < 0 is provided: m_progressBar->setMaximum((percent < 0) ? 0 : 100); - if (percent < 0) { - percent = 0; - } else if (percent > 100) { - percent = 100; - } - + percent = qBound(0, percent, 100); const bool progressRestarted = (percent < 100) && (percent < m_progress); m_progress = percent; - if (m_messageLabel->type() == KonqStatusBarMessageLabel::Error) { - // Don't update any widget or status bar text if an - // error message is shown - return; - } - if (progressRestarted && !m_progressBar->isVisible()) { // Show the progress bar delayed: In the case if 100 % are reached within // a short time, no progress bar will be shown at all. @@ -229,54 +197,73 @@ void DolphinStatusBar::setProgress(int percent) m_showProgressBarTimer->stop(); updateProgressInfo(); } +} - const QString defaultText = m_messageLabel->defaultText(); - const QString msg(m_messageLabel->text()); - if ((percent == 0) && !msg.isEmpty()) { - setMessage(QString(), Default); - } else if ((percent == 100) && (msg != defaultText)) { - setMessage(defaultText, Default); - } +int DolphinStatusBar::progress() const +{ + return m_progress; } -void DolphinStatusBar::clear() +void DolphinStatusBar::resetToDefaultText() { - setMessage(m_messageLabel->defaultText(), Default); + m_text.clear(); + + QTime currentTime; + if (currentTime.msecsTo(m_textTimestamp) < UpdateDelay) { + m_delayUpdateTimer->start(); + } else { + updateLabelText(); + } } void DolphinStatusBar::setDefaultText(const QString& text) { - m_messageLabel->setDefaultText(text); + m_defaultText = text; + updateLabelText(); } QString DolphinStatusBar::defaultText() const { - return m_messageLabel->defaultText(); + return m_defaultText; } -void DolphinStatusBar::refresh() +void DolphinStatusBar::setUrl(const QUrl& url) +{ + m_spaceInfo->setUrl(url); +} + +QUrl DolphinStatusBar::url() const +{ + return m_spaceInfo->url(); +} + +void DolphinStatusBar::setZoomLevel(int zoomLevel) +{ + if (zoomLevel != m_zoomSlider->value()) { + m_zoomSlider->setValue(zoomLevel); + } +} + +int DolphinStatusBar::zoomLevel() const +{ + return m_zoomSlider->value(); +} + +void DolphinStatusBar::readSettings() { setExtensionsVisible(true); } +void DolphinStatusBar::updateSpaceInfo() +{ + m_spaceInfo->update(); +} + void DolphinStatusBar::contextMenuEvent(QContextMenuEvent* event) { - Q_UNUSED(event); - - KMenu menu(this); - - QAction* copyAction = 0; - switch (type()) { - case Default: - case OperationCompleted: - case Information: - copyAction = menu.addAction(i18nc("@action:inmenu", "Copy Information Message")); - break; - case Error: - copyAction = menu.addAction(i18nc("@action:inmenu", "Copy Error Message")); - break; - default: break; - } + Q_UNUSED(event) + + QMenu menu(this); QAction* showZoomSliderAction = menu.addAction(i18nc("@action:inmenu", "Show Zoom Slider")); showZoomSliderAction->setCheckable(true); @@ -287,11 +274,7 @@ void DolphinStatusBar::contextMenuEvent(QContextMenuEvent* event) showSpaceInfoAction->setChecked(GeneralSettings::showSpaceInfo()); const QAction* action = menu.exec(QCursor::pos()); - if (action == copyAction) { - QMimeData* mimeData = new QMimeData(); - mimeData->setText(message()); - QApplication::clipboard()->setMimeData(mimeData); - } else if (action == showZoomSliderAction) { + if (action == showZoomSliderAction) { const bool visible = showZoomSliderAction->isChecked(); GeneralSettings::setShowZoomSlider(visible); m_zoomSlider->setVisible(visible); @@ -302,17 +285,6 @@ void DolphinStatusBar::contextMenuEvent(QContextMenuEvent* event) } } -void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url) -{ - m_spaceInfo->setUrl(url); -} - -void DolphinStatusBar::setZoomLevel(int zoomLevel) -{ - m_view->setZoomLevel(zoomLevel); - updateZoomSliderToolTip(zoomLevel); -} - void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel) { updateZoomSliderToolTip(zoomLevel); @@ -323,39 +295,35 @@ void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel) QApplication::sendEvent(m_zoomSlider, &toolTipEvent); } -void DolphinStatusBar::slotZoomLevelChanged(int current, int previous) -{ - Q_UNUSED(previous); - m_zoomSlider->setValue(current); -} - -void DolphinStatusBar::slotPreviewsShownChanged(bool shown) -{ - Q_UNUSED(shown); - // The zoom level might be different with/without previews -> update the zoom slider. - m_zoomSlider->setValue(m_view->zoomLevel()); -} - void DolphinStatusBar::updateProgressInfo() { - const bool isErrorShown = (m_messageLabel->type() == KonqStatusBarMessageLabel::Error); if (m_progress < 100) { // Show the progress information and hide the extensions + m_stopButton->show(); + m_progressTextLabel->show(); + m_progressBar->show(); setExtensionsVisible(false); - if (!isErrorShown) { - m_stopButton->show(); - m_progressText->show(); - m_progressBar->show(); - } } else { // Hide the progress information and show the extensions m_stopButton->hide(); - m_progressText->hide(); + m_progressTextLabel->hide(); m_progressBar->hide(); setExtensionsVisible(true); } } +void DolphinStatusBar::updateLabelText() +{ + const QString text = m_text.isEmpty() ? m_defaultText : m_text; + m_label->setText(text); +} + +void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel) +{ + const int size = ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel); + m_zoomSlider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); +} + void DolphinStatusBar::setExtensionsVisible(bool visible) { bool showSpaceInfo = visible; @@ -368,10 +336,3 @@ void DolphinStatusBar::setExtensionsVisible(bool visible) m_zoomSlider->setVisible(showZoomSlider); } -void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel) -{ - const int size = ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel); - m_zoomSlider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); -} - -#include "dolphinstatusbar.moc"