X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/99eacd9f56acf4ad21994508ee824b1ce1594be1..3c77ffe832a00f405e474f11da7b39d37a410a5b:/src/statusbar/dolphinstatusbar.cpp diff --git a/src/statusbar/dolphinstatusbar.cpp b/src/statusbar/dolphinstatusbar.cpp index aaa302a15..681fbf407 100644 --- a/src/statusbar/dolphinstatusbar.cpp +++ b/src/statusbar/dolphinstatusbar.cpp @@ -19,55 +19,50 @@ ***************************************************************************/ #include "dolphinstatusbar.h" -#include "settings/dolphinsettings.h" -#include "dolphinview.h" + #include "dolphin_generalsettings.h" -#include "statusbarmessagelabel.h" + +#include +#include +#include +#include +#include + #include "statusbarspaceinfo.h" -#include "zoomlevelinfo.h" #include +#include #include #include #include #include +#include #include -#include -#include -#include -#include +#include +#include DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) : - KHBox(parent), + QWidget(parent), m_view(view), m_messageLabel(0), m_spaceInfo(0), - m_zoomWidget(0), - m_zoomOut(0), m_zoomSlider(0), - m_zoomIn(0), m_progressBar(0), - m_progress(100) + m_stopButton(0), + m_progress(100), + m_showProgressBarTimer(0), + m_messageTimeStamp() { - setMargin(0); - setSpacing(4); - - connect(m_view, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(updateSpaceInfoContent(const KUrl&))); - - // initialize message label - m_messageLabel = new StatusBarMessageLabel(this); - m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + connect(m_view, SIGNAL(urlChanged(KUrl)), + this, SLOT(updateSpaceInfoContent(KUrl))); - // initialize zoom slider - m_zoomWidget = new QWidget(this); + // Initialize message label + m_messageLabel = new KonqStatusBarMessageLabel(this); - m_zoomOut = new QToolButton(m_zoomWidget); - m_zoomOut->setIcon(KIcon("zoom-out")); - m_zoomOut->setAutoRaise(true); - - m_zoomSlider = new QSlider(Qt::Horizontal, m_zoomWidget); + // Initialize zoom widget + m_zoomSlider = new QSlider(Qt::Horizontal, this); + m_zoomSlider->setAccessibleName(i18n("Zoom slider")); m_zoomSlider->setPageStep(1); const int min = ZoomLevelInfo::minimumLevel(); @@ -76,43 +71,57 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) : m_zoomSlider->setValue(view->zoomLevel()); updateZoomSliderToolTip(view->zoomLevel()); - m_zoomIn = new QToolButton(m_zoomWidget); - m_zoomIn->setIcon(KIcon("zoom-in")); - m_zoomIn->setAutoRaise(true); - - QHBoxLayout* zoomWidgetLayout = new QHBoxLayout(m_zoomWidget); - zoomWidgetLayout->setSpacing(0); - zoomWidgetLayout->setMargin(0); - zoomWidgetLayout->addWidget(m_zoomOut); - zoomWidgetLayout->addWidget(m_zoomSlider); - zoomWidgetLayout->addWidget(m_zoomIn); - 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)), m_zoomSlider, SLOT(setValue(int))); - connect(m_zoomOut, SIGNAL(clicked()), this, SLOT(zoomOut())); - connect(m_zoomIn, SIGNAL(clicked()), this, SLOT(zoomIn())); + connect(m_view, SIGNAL(zoomLevelChanged(int,int)), this, SLOT(slotZoomLevelChanged(int,int))); - // initialize space information + // Initialize space information m_spaceInfo = new StatusBarSpaceInfo(this); m_spaceInfo->setUrl(m_view->url()); - // initialize progress information + // Initialize progress information + m_stopButton = new QToolButton(this); + m_stopButton->setIcon(KIcon("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->hide(); + connect(m_stopButton, SIGNAL(clicked()), this, SIGNAL(stopPressed())); + m_progressText = new QLabel(this); m_progressText->hide(); m_progressBar = new QProgressBar(this); m_progressBar->hide(); - // initialize sizes + m_showProgressBarTimer = new QTimer(this); + m_showProgressBarTimer->setInterval(1000); + m_showProgressBarTimer->setSingleShot(true); + connect(m_showProgressBarTimer, SIGNAL(timeout()), this, SLOT(updateProgressInfo())); + + // Initialize top layout and size policies const int fontHeight = QFontMetrics(m_messageLabel->font()).height(); - const int zoomWidgetHeight = m_zoomWidget->minimumSizeHint().height(); - const int contentHeight = (fontHeight < zoomWidgetHeight) ? zoomWidgetHeight : fontHeight; + const int zoomSliderHeight = m_zoomSlider->minimumSizeHint().height(); + const int contentHeight = qMax(fontHeight, zoomSliderHeight); m_messageLabel->setMinimumTextHeight(contentHeight); - m_spaceInfo->setFixedHeight(contentHeight); - m_progressBar->setFixedSize(200, contentHeight); - m_zoomWidget->setFixedSize(150, contentHeight); + + m_spaceInfo->setMaximumSize(200, contentHeight - 5); + m_spaceInfo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + m_progressBar->setMaximumSize(200, contentHeight); + m_zoomSlider->setMaximumSize(150, contentHeight); + m_zoomSlider->setMinimumWidth(30); + + QHBoxLayout* topLayout = new QHBoxLayout(this); + topLayout->setMargin(0); + topLayout->setSpacing(4); + topLayout->addWidget(m_messageLabel); + topLayout->addWidget(m_zoomSlider); + topLayout->addWidget(m_spaceInfo); + topLayout->addWidget(m_stopButton); + topLayout->addWidget(m_progressText); + topLayout->addWidget(m_progressBar); setExtensionsVisible(true); } @@ -124,30 +133,47 @@ DolphinStatusBar::~DolphinStatusBar() void DolphinStatusBar::setMessage(const QString& msg, Type type) { - if (msg.isEmpty()) { - // show the default text as fallback - clear(); - return; + 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; } - if ((msg == m_messageLabel->text()) && (type == m_messageLabel->type())) { + KonqStatusBarMessageLabel::Type konqType = static_cast(type); + if ((message == m_messageLabel->text()) && (konqType == m_messageLabel->type())) { // the message is already shown return; } - m_messageLabel->setMessage(msg, type); + 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; + } - const int widthGap = m_messageLabel->widthGap(); - if (widthGap > 0) { - m_progressBar->hide(); - m_progressText->hide(); + m_messageLabel->setMessage(message, konqType); + if (type != Default) { + m_messageTimeStamp = currentTime; } - assureVisibleText(); } DolphinStatusBar::Type DolphinStatusBar::type() const { - return m_messageLabel->type(); + return static_cast(m_messageLabel->type()); } QString DolphinStatusBar::message() const @@ -160,6 +186,11 @@ void DolphinStatusBar::setProgressText(const QString& text) m_progressText->setText(text); } +int DolphinStatusBar::progress() const +{ + return m_progress; +} + QString DolphinStatusBar::progressText() const { return m_progressText->text(); @@ -167,25 +198,38 @@ QString DolphinStatusBar::progressText() const 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; } + const bool progressRestarted = (percent < 100) && (percent < m_progress); m_progress = percent; - if (m_messageLabel->type() == Error) { - // don't update any widget or status bar text if an + 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. + m_showProgressBarTimer->start(); + } + m_progressBar->setValue(m_progress); - if (!m_progressBar->isVisible() || (percent == 100)) { - QTimer::singleShot(300, this, SLOT(updateProgressInfo())); + if (percent == 100) { + // The end of the progress has been reached. Assure that the progress bar + // gets hidden and the extensions widgets get visible again. + m_showProgressBarTimer->stop(); + updateProgressInfo(); } - const QString& defaultText = m_messageLabel->defaultText(); + const QString defaultText = m_messageLabel->defaultText(); const QString msg(m_messageLabel->text()); if ((percent == 0) && !msg.isEmpty()) { setMessage(QString(), Default); @@ -204,7 +248,7 @@ void DolphinStatusBar::setDefaultText(const QString& text) m_messageLabel->setDefaultText(text); } -const QString& DolphinStatusBar::defaultText() const +QString DolphinStatusBar::defaultText() const { return m_messageLabel->defaultText(); } @@ -212,87 +256,62 @@ const QString& DolphinStatusBar::defaultText() const void DolphinStatusBar::refresh() { setExtensionsVisible(true); - assureVisibleText(); } -void DolphinStatusBar::resizeEvent(QResizeEvent* event) +void DolphinStatusBar::contextMenuEvent(QContextMenuEvent* event) { - // It is important to hide the widgets before invoking - // QWidget::resizeEvent(), otherwise it is possible that - // the dock widgets are shrinked when having a small - // statusbar width (bug #202147). - m_zoomWidget->hide(); - m_spaceInfo->hide(); - - QWidget::resizeEvent(event); - QMetaObject::invokeMethod(this, "assureVisibleText", Qt::QueuedConnection); -} + 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; + } -void DolphinStatusBar::updateProgressInfo() -{ - const bool isErrorShown = (m_messageLabel->type() == Error); - if (m_progress < 100) { - // show the progress information and hide the extensions - setExtensionsVisible(false); - if (!isErrorShown) { - m_progressText->show(); - m_progressBar->show(); - } - } else { - // hide the progress information and show the extensions - m_progressText->hide(); - m_progressBar->hide(); - assureVisibleText(); + QAction* showZoomSliderAction = menu.addAction(i18nc("@action:inmenu", "Show Zoom Slider")); + showZoomSliderAction->setCheckable(true); + showZoomSliderAction->setChecked(GeneralSettings::showZoomSlider()); + + QAction* showSpaceInfoAction = menu.addAction(i18nc("@action:inmenu", "Show Space Information")); + showSpaceInfoAction->setCheckable(true); + 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) { + const bool visible = showZoomSliderAction->isChecked(); + GeneralSettings::setShowZoomSlider(visible); + m_zoomSlider->setVisible(visible); + } else if (action == showSpaceInfoAction) { + const bool visible = showSpaceInfoAction->isChecked(); + GeneralSettings::setShowSpaceInfo(visible); + m_spaceInfo->setVisible(visible); } } void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url) { m_spaceInfo->setUrl(url); - assureVisibleText(); } void DolphinStatusBar::setZoomLevel(int zoomLevel) { - m_zoomOut->setEnabled(zoomLevel > m_zoomSlider->minimum()); - m_zoomIn->setEnabled(zoomLevel < m_zoomSlider->maximum()); m_view->setZoomLevel(zoomLevel); updateZoomSliderToolTip(zoomLevel); } -void DolphinStatusBar::assureVisibleText() -{ - const int widthGap = m_messageLabel->widthGap(); - if (m_spaceInfo->isVisible() || m_zoomWidget->isVisible()) { - // At least the space information or the zoom slider is shown. - // Hide them if the status bar text does not fit into the available width. - if (widthGap > 0) { - setExtensionsVisible(false); - } - } else if (!m_progressBar->isVisible()) { - const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - const int spaceInfoWidth = settings->showSpaceInfo() ? m_spaceInfo->minimumWidth() : 0; - const int zoomWidgetWidth = settings->showZoomSlider() ? m_zoomWidget->minimumWidth() : 0; - const int widgetsWidth = spaceInfoWidth + zoomWidgetWidth; - - if (widthGap + widgetsWidth <= 0) { - setExtensionsVisible(true); - } - } -} - -void DolphinStatusBar::zoomOut() -{ - const int value = m_zoomSlider->value(); - m_zoomSlider->setValue(value - 1); -} - -void DolphinStatusBar::zoomIn() -{ - const int value = m_zoomSlider->value(); - m_zoomSlider->setValue(value + 1); -} - void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel) { updateZoomSliderToolTip(zoomLevel); @@ -303,18 +322,42 @@ 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::updateProgressInfo() +{ + const bool isErrorShown = (m_messageLabel->type() == KonqStatusBarMessageLabel::Error); + if (m_progress < 100) { + // Show the progress information and hide the extensions + 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_progressBar->hide(); + setExtensionsVisible(true); + } +} + void DolphinStatusBar::setExtensionsVisible(bool visible) { - bool spaceInfoVisible = visible; - bool zoomSliderVisible = visible; + bool showSpaceInfo = visible; + bool showZoomSlider = visible; if (visible) { - const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - spaceInfoVisible = settings->showSpaceInfo(); - zoomSliderVisible = settings->showZoomSlider(); + showSpaceInfo = GeneralSettings::showSpaceInfo(); + showZoomSlider = GeneralSettings::showZoomSlider(); } - - m_spaceInfo->setVisible(spaceInfoVisible); - m_zoomWidget->setVisible(zoomSliderVisible); + m_spaceInfo->setVisible(showSpaceInfo); + m_zoomSlider->setVisible(showZoomSlider); } void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel)