]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/infosidebarpage.cpp
fixing more warnings
[dolphin.git] / src / infosidebarpage.cpp
index b9e345f62fd54b51cb05e25699d56a460d6bb567..b32f83cd148fb2d6c2ac365bed6456fdb87097a1 100644 (file)
@@ -25,7 +25,7 @@
 #include <qlabel.h>
 #include <qtimer.h>
 #include <qpushbutton.h>
-#include <q3vbox.h>
+
 #include <q3vgroupbox.h>
 #include <q3popupmenu.h>
 #include <qpainter.h>
 #include <kdialog.h>
 #include <kglobalsettings.h>
 #include <kfilemetainfo.h>
+#include <kvbox.h>
 
-#include "dolphin.h"
+#include "dolphinmainwindow.h"
 #include "pixmapviewer.h"
 #include "dolphinsettings.h"
 
-InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
-    SidebarPage(parent),
+InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
+    SidebarPage(mainWindow, parent),
     m_multipleSelection(false),
     m_pendingPreview(false),
     m_timer(0),
@@ -94,7 +95,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
     sep2->setFixedHeight(1);
 
     // actions
-    m_actionBox = new Q3VBox(this);
+    m_actionBox = new KVBox(this);
     m_actionBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
 
     // Add a dummy widget with no restriction regarding a vertical resizing.
@@ -110,7 +111,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
     layout->addWidget(m_actionBox);
     layout->addWidget(dummy);
 
-    connect(&Dolphin::mainWin(), SIGNAL(selectionChanged()),
+    connect(mainWindow, SIGNAL(selectionChanged()),
             this, SLOT(showItemInfo()));
 
     connectToActiveView();
@@ -131,7 +132,8 @@ void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url)
 
     if (!url.isEmpty() && !m_multipleSelection) {
         m_urlCandidate = url;
-        m_timer->start(300, true);
+        m_timer->setSingleShot(true);
+        m_timer->start(300);
     }
 }
 
@@ -140,7 +142,7 @@ void InfoSidebarPage::requestItemInfo(const KUrl& url)
     cancelRequest();
 
     if (!url.isEmpty() && !m_multipleSelection) {
-        m_shownURL = url;
+        m_shownUrl = url;
         showItemInfo();
     }
 }
@@ -152,9 +154,9 @@ void InfoSidebarPage::showItemInfo()
     m_multipleSelection = false;
 
     // show the preview...
-    DolphinView* view = Dolphin::mainWin().activeView();
-    const KFileItemList* selectedItems = view->selectedItems();
-    if ((selectedItems != 0) && selectedItems->count() > 1) {
+    DolphinView* view = mainWindow()->activeView();
+    const KFileItemList selectedItems = view->selectedItems();
+    if (selectedItems.count() > 1) {
         m_multipleSelection = true;
     }
 
@@ -164,12 +166,12 @@ void InfoSidebarPage::showItemInfo()
                                            K3Icon::NoGroup,
                                            K3Icon::SizeEnormous);
         m_preview->setPixmap(icon);
-        m_name->setText(i18n("%1 items selected").arg(selectedItems->count()));
+        m_name->setText(i18n("%1 items selected",selectedItems.count()));
     }
     else if (!applyBookmark()) {
         // try to get a preview pixmap from the item...
         KUrl::List list;
-        list.append(m_shownURL);
+        list.append(m_shownUrl);
 
         m_pendingPreview = true;
         m_preview->setPixmap(QPixmap());
@@ -183,7 +185,7 @@ void InfoSidebarPage::showItemInfo()
                 this, SLOT(slotPreviewFailed(const KFileItem*)));
 
         QString text("<b>");
-        text.append(m_shownURL.fileName());
+        text.append(m_shownUrl.fileName());
         text.append("</b>");
         m_name->setText(text);
     }
@@ -194,7 +196,7 @@ void InfoSidebarPage::showItemInfo()
 
 void InfoSidebarPage::slotTimeout()
 {
-    m_shownURL = m_urlCandidate;
+    m_shownUrl = m_urlCandidate;
     showItemInfo();
 }
 
@@ -217,13 +219,13 @@ void InfoSidebarPage::gotPreview(const KFileItem* /* item */,
 
 void InfoSidebarPage::startService(int index)
 {
-    DolphinView* view = Dolphin::mainWin().activeView();
+    DolphinView* view = mainWindow()->activeView();
     if (view->hasSelection()) {
-        KUrl::List selectedURLs = view->selectedURLs();
-        KDEDesktopMimeType::executeService(selectedURLs, m_actionsVector[index]);
+        KUrl::List selectedUrls = view->selectedUrls();
+        KDEDesktopMimeType::executeService(selectedUrls, m_actionsVector[index]);
     }
     else {
-        KDEDesktopMimeType::executeService(m_shownURL, m_actionsVector[index]);
+        KDEDesktopMimeType::executeService(m_shownUrl, m_actionsVector[index]);
     }
 }
 
@@ -231,13 +233,13 @@ void InfoSidebarPage::connectToActiveView()
 {
     cancelRequest();
 
-    DolphinView* view = Dolphin::mainWin().activeView();
+    DolphinView* view = mainWindow()->activeView();
     connect(view, SIGNAL(signalRequestItemInfo(const KUrl&)),
             this, SLOT(requestDelayedItemInfo(const KUrl&)));
-    connect(view, SIGNAL(signalURLChanged(const KUrl&)),
+    connect(view, SIGNAL(signalUrlChanged(const KUrl&)),
             this, SLOT(requestItemInfo(const KUrl&)));
 
-    m_shownURL = view->url();
+    m_shownUrl = view->url();
     showItemInfo();
 }
 
@@ -246,7 +248,7 @@ bool InfoSidebarPage::applyBookmark()
     KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root();
     KBookmark bookmark = root.first();
     while (!bookmark.isNull()) {
-        if (m_shownURL.equals(bookmark.url(), true)) {
+        if (m_shownUrl.equals(bookmark.url(), KUrl::CompareWithoutTrailingSlash)) {
             QString text("<b>");
             text.append(bookmark.text());
             text.append("</b>");
@@ -278,9 +280,9 @@ void InfoSidebarPage::createMetaInfo()
     // The methods beginInfoLines(), addInfoLine() and endInfoLines()
     // take care of this.
     beginInfoLines();
-    DolphinView* view = Dolphin::mainWin().activeView();
+    DolphinView* view = mainWindow()->activeView();
     if (!view->hasSelection()) {
-        KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownURL);
+        KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
         fileItem.refresh();
 
         if (fileItem.isDir()) {
@@ -426,14 +428,12 @@ void InfoSidebarPage::insertActions()
 
     // The algorithm for searching the available actions works on a list
     // of KFileItems. If no selection is given, a temporary KFileItem
-    // by the given URL 'url' is created and added to the list.
-    KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownURL);
-    KFileItemList localList;
-    const KFileItemList* itemList = Dolphin::mainWin().activeView()->selectedItems();
-    if ((itemList == 0) || itemList->isEmpty()) {
+    // by the given Url 'url' is created and added to the list.
+    KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
+    KFileItemList itemList = mainWindow()->activeView()->selectedItems();
+    if (itemList.isEmpty()) {
         fileItem.refresh();
-        localList.append(&fileItem);
-        itemList = &localList;
+        itemList.append(&fileItem);
     }
 
     // 'itemList' contains now all KFileItems, where an item information should be shown.
@@ -457,12 +457,11 @@ void InfoSidebarPage::insertActions()
                     if ((*it) == "all/allfiles") {
                         // The service type is valid for all files, but not for directories.
                         // Check whether the selected items only consist of files...
-                        KFileItemListIterator mimeIt(*itemList);
-                        KFileItem* item = 0;
+                        QListIterator<KFileItem*> mimeIt(itemList);
                         insert = true;
-                        while (insert && ((item = mimeIt.current()) != 0)) {
+                        while (insert && mimeIt.hasNext()) {
+                            KFileItem* item = mimeIt.next();
                             insert = !item->isDir();
-                            ++mimeIt;
                         }
                     }
 
@@ -470,17 +469,16 @@ void InfoSidebarPage::insertActions()
                         // Check whether the MIME types of all selected files match
                         // to the mimetype of the service action. As soon as one MIME
                         // type does not match, no service menu is shown at all.
-                        KFileItemListIterator mimeIt(*itemList);
-                        KFileItem* item = 0;
+                        QListIterator<KFileItem*> mimeIt(itemList);
                         insert = true;
-                        while (insert && ((item = mimeIt.current()) != 0)) {
-                            const QString mimeType((*mimeIt)->mimetype());
-                            const QString mimeGroup(mimeType.left(mimeType.find('/')));
+                        while (insert && mimeIt.hasNext()) {
+                            KFileItem* item = mimeIt.next();
+                            const QString mimeType(item->mimetype());
+                            const QString mimeGroup(mimeType.left(mimeType.indexOf('/')));
 
                             insert  = (*it == mimeType) ||
                                       ((*it).right(1) == "*") &&
-                                      ((*it).left((*it).find('/')) == mimeGroup);
-                            ++mimeIt;
+                                      ((*it).left((*it).indexOf('/')) == mimeGroup);
                         }
                     }
 
@@ -539,7 +537,7 @@ ServiceButton::ServiceButton(const QIcon& icon,
     m_hover(false),
     m_index(index)
 {
-    setEraseColor(colorGroup().background());
+    setEraseColor(palette().brush(QPalette::Background).color());
     setFocusPolicy(Qt::NoFocus);
     connect(this, SIGNAL(released()),
             this, SLOT(slotReleased()));
@@ -549,8 +547,9 @@ ServiceButton::~ServiceButton()
 {
 }
 
-void ServiceButton::drawButton(QPainter* painter)
+void ServiceButton::paintEvent(QPaintEvent* event)
 {
+    QPainter painter(this);
     const int buttonWidth  = width();
     const int buttonHeight = height();
 
@@ -561,14 +560,14 @@ void ServiceButton::drawButton(QPainter* painter)
         foregroundColor = KGlobalSettings::highlightedTextColor();
     }
     else {
-        backgroundColor = colorGroup().background();
+        backgroundColor = palette().brush(QPalette::Background).color();
         foregroundColor = KGlobalSettings::buttonTextColor();
     }
 
     // draw button background
-    painter->setPen(NoPen);
-    painter->setBrush(backgroundColor);
-    painter->drawRect(0, 0, buttonWidth, buttonHeight);
+    painter.setPen(Qt::NoPen);
+    painter.setBrush(backgroundColor);
+    painter.drawRect(0, 0, buttonWidth, buttonHeight);
 
     const int spacing = KDialog::spacingHint();
 
@@ -577,24 +576,24 @@ void ServiceButton::drawButton(QPainter* painter)
     const int y = (buttonHeight - K3Icon::SizeSmall) / 2;
     const QIcon* set = iconSet();
     if (set != 0) {
-        painter->drawPixmap(x, y, set->pixmap(QIcon::Small, QIcon::Normal));
+        painter.drawPixmap(x, y, set->pixmap(QIcon::Small, QIcon::Normal));
     }
     x += K3Icon::SizeSmall + spacing;
 
     // draw text
-    painter->setPen(foregroundColor);
+    painter.setPen(foregroundColor);
 
     const int textWidth = buttonWidth - x;
     QFontMetrics fontMetrics(font());
     const bool clipped = fontMetrics.width(text()) >= textWidth;
     //const int align = clipped ? Qt::AlignVCenter : Qt::AlignCenter;
-    painter->drawText(QRect(x, 0, textWidth, buttonHeight), Qt::AlignVCenter, text());
+    painter.drawText(QRect(x, 0, textWidth, buttonHeight), Qt::AlignVCenter, text());
 
     if (clipped) {
         // Blend the right area of the text with the background, as the
         // text is clipped.
         // TODO #1: use alpha blending in Qt4 instead of drawing the text that often
-        // TODO #2: same code as in URLNavigatorButton::drawButton() -> provide helper class?
+        // TODO #2: same code as in UrlNavigatorButton::drawButton() -> provide helper class?
         const int blendSteps = 16;
 
         QColor blendColor(backgroundColor);
@@ -602,9 +601,9 @@ void ServiceButton::drawButton(QPainter* painter)
         const int greenInc = (foregroundColor.green() - backgroundColor.green()) / blendSteps;
         const int blueInc  = (foregroundColor.blue()  - backgroundColor.blue())  / blendSteps;
         for (int i = 0; i < blendSteps; ++i) {
-            painter->setClipRect(QRect(x + textWidth - i, 0, 1, buttonHeight));
-            painter->setPen(blendColor);
-            painter->drawText(QRect(x, 0, textWidth, buttonHeight), Qt::AlignVCenter, text());
+            painter.setClipRect(QRect(x + textWidth - i, 0, 1, buttonHeight));
+            painter.setPen(blendColor);
+            painter.drawText(QRect(x, 0, textWidth, buttonHeight), Qt::AlignVCenter, text());
 
             blendColor.setRgb(blendColor.red()   + redInc,
                               blendColor.green() + greenInc,
@@ -632,3 +631,4 @@ void ServiceButton::slotReleased()
     emit requestServiceStart(m_index);
 }
 
+#include "infosidebarpage.moc"