[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/apps/konqueror/src
From:       Aurélien Gâteau <agateau () kde ! org>
Date:       2010-08-24 8:58:01
Message-ID: 20100824090042.5E34EAC857 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1167292 by gateau:

Moved throbber to the toolbar

 M  +15 -79    konqanimatedlogo.cpp  
 M  +7 -11     konqanimatedlogo_p.h  
 M  +7 -2      konqmainwindow.cpp  
 M  +2 -1      konqueror.rc  


--- trunk/KDE/kdebase/apps/konqueror/src/konqanimatedlogo.cpp #1167291:1167292
@@ -24,9 +24,7 @@
 #include <KDE/KIconLoader>
 
 #include <QtCore/QEvent>
-#include <QtGui/QMenuBar>
-#include <QtGui/QStyle>
-#include <QtGui/QStyleOptionMenuItem>
+#include <QtGui/QToolBar>
 
 KonqAnimatedLogo::KonqAnimatedLogo(QWidget *parent)
     : KAnimatedButton(parent)
@@ -34,99 +32,37 @@
     setAutoRaise(true);
     setFocusPolicy(Qt::NoFocus);
     setToolButtonStyle(Qt::ToolButtonIconOnly);
-    setAnimatedLogoSize(maxThrobberHeight());
-    if (qobject_cast<QMenuBar *>(parent))
-        parent->installEventFilter(this);
+    QToolBar * bar = qobject_cast<QToolBar *>(parent);
+    if (bar) {
+        connectToToolBar(bar);
 }
-
-KonqAnimatedLogo::~KonqAnimatedLogo()
-{
-    if (parentWidget())
-        parentWidget()->removeEventFilter(this);
 }
 
-QSize KonqAnimatedLogo::sizeHint() const
-{
-    return m_size;
-}
-
 void KonqAnimatedLogo::changeEvent(QEvent *event)
 {
     KAnimatedButton::changeEvent(event);
     if (event->type() == QEvent::ParentAboutToChange) {
-        if (parentWidget())
-            parentWidget()->removeEventFilter(this);
+        if (parentWidget()) {
+            disconnect(parentWidget(), SIGNAL(iconSizeChanged(QSize)), this, \
SLOT(setAnimatedLogoSize())); +        }
     } else if (event->type() == QEvent::ParentChange) {
-        if (qobject_cast<QMenuBar *>(parentWidget()))
-            parentWidget()->installEventFilter(this);
+        QToolBar *bar = qobject_cast<QToolBar *>(parentWidget());
+        if (bar) {
+            connectToToolBar(bar);
     }
 }
-
-bool KonqAnimatedLogo::eventFilter(QObject *watched, QEvent *event)
-{
-    if (qobject_cast<QWidget *>(watched) == parentWidget()) {
-        if (event->type() == QEvent::StyleChange || event->type() == \
                QEvent::FontChange
-            || event->type() == QEvent::ApplicationFontChange) {
-            // make sure the logo is resized before the menu bar gets the
-            // font change event
-            setAnimatedLogoSize(maxThrobberHeight());
         }
-    }
-    return KAnimatedButton::eventFilter(watched, event);
-}
 
-int KonqAnimatedLogo::maxThrobberHeight()
+void KonqAnimatedLogo::connectToToolBar(QToolBar *bar)
 {
-    QMenuBar *menuBar = qobject_cast<QMenuBar *>(parentWidget());
-    if (!menuBar)
-        return 22;
-
-    // This comes from QMenuBar::sizeHint and QMenuBarPrivate::calcActionRects
-    const QFontMetrics fm = menuBar->fontMetrics();
-    QSize sz(100, fm.height());
-    //let the style modify the above size..
-    QStyleOptionMenuItem opt;
-    opt.fontMetrics = fm;
-    opt.state = QStyle::State_Enabled;
-    opt.menuRect = menuBar->rect();
-    opt.text = "dummy";
-    sz = menuBar->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, \
                menuBar);
-    //kDebug() << "maxThrobberHeight=" << sz.height();
-    return sz.height();
+    setAnimatedLogoSize(bar->iconSize());
+    connect(bar, SIGNAL(iconSizeChanged(QSize)), SLOT(setAnimatedLogoSize(QSize)));
 }
 
-void KonqAnimatedLogo::setAnimatedLogoSize(int buttonHeight)
+void KonqAnimatedLogo::setAnimatedLogoSize(const QSize &size)
 {
-    // This gives the best results: we force a bigger icon size onto the style, and \
                it'll just have to eat up its margin.
-    // So we don't need to ask sizeFromContents at all.
-    int iconSize = buttonHeight - 4;
-#if 0
-    QStyleOptionToolButton opt;
-    opt.initFrom(m_paAnimatedLogo);
-    const QSize finalSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, \
                opt.iconSize, m_paAnimatedLogo);
-    //kDebug() << "throbberIconSize=" << buttonHeight << "-" << finalSize.height() - \
                opt.iconSize.height();
-    int iconSize = buttonHeight - (finalSize.height() - opt.iconSize.height());
-#endif
-
-    m_size = QSize(buttonHeight, buttonHeight);
-    setFixedSize(m_size);
-
-    //kDebug() << "buttonHeight=" << buttonHeight << "max iconSize=" << iconSize;
-    if ( iconSize < KIconLoader::SizeSmallMedium )
-        iconSize = KIconLoader::SizeSmall;
-    else if ( iconSize < KIconLoader::SizeMedium  )
-        iconSize = KIconLoader::SizeSmallMedium;
-    else if ( iconSize < KIconLoader::SizeLarge )
-        iconSize = KIconLoader::SizeMedium ;
-    else
-        iconSize = KIconLoader::SizeLarge;
-    //kDebug() << "final iconSize=" << iconSize;
-    if (iconDimensions() != iconSize) {
-        setIconSize(QSize(iconSize, iconSize));
-        if (!icons().isEmpty()) {
+    setIconSize(size);
             updateIcons();
         }
-    }
-}
 
 #include "konqanimatedlogo_p.moc"
--- trunk/KDE/kdebase/apps/konqueror/src/konqanimatedlogo_p.h #1167291:1167292
@@ -24,30 +24,26 @@
 
 #include <KDE/KAnimatedButton>
 
+class QToolBar;
+
 class KonqAnimatedLogo : public KAnimatedButton
 {
     Q_OBJECT
 
 public:
     /**
-     * Create an animated logo button suitable sized for @p menuBar
-     *
-     * The button is not added to the menu bar.
+     * Creates an animated logo button which follows the toolbar icon size
      */
     KonqAnimatedLogo(QWidget *parent = 0);
-    ~KonqAnimatedLogo();
 
-    QSize sizeHint() const;
-
 protected:
-    bool eventFilter(QObject *watched, QEvent *event);
     void changeEvent(QEvent *event);
 
-private:
-    int maxThrobberHeight();
-    void setAnimatedLogoSize(int buttonHeight);
+private Q_SLOTS:
+    void setAnimatedLogoSize(const QSize &);
 
-    QSize m_size;
+private:
+    void connectToToolBar(QToolBar *);
 };
 
 #endif // KONQANIMATEDLOGO_P_H
--- trunk/KDE/kdebase/apps/konqueror/src/konqmainwindow.cpp #1167291:1167292
@@ -3716,9 +3716,14 @@
   connect(m_paStop, SIGNAL(triggered()), SLOT( slotStop() ));
   m_paStop->setShortcut(Qt::Key_Escape);
 
-  m_paAnimatedLogo = new KonqAnimatedLogo( menuBar() );
-  menuBar()->setCornerWidget(m_paAnimatedLogo);
+  m_paAnimatedLogo = new KonqAnimatedLogo;
   m_paAnimatedLogo->setIcons("process-working-kde");
+  KAction *logoAction = new KAction( this );
+  actionCollection()->addAction( "konq_logo", logoAction );
+  logoAction->setDefaultWidget( m_paAnimatedLogo );
+  // Set icon and text so that it's easier to figure out what the action is in the \
toolbar editor +  logoAction->setText( i18n("Throbber") );
+  logoAction->setIcon( KIcon("kde") );
 
   // Location bar
   m_locationLabel = new KonqDraggableLabel( this, i18n("L&ocation: ") );
--- trunk/KDE/kdebase/apps/konqueror/src/konqueror.rc #1167291:1167292
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <!DOCTYPE gui SYSTEM "kpartgui.dtd">
-<gui name="Konqueror" version="68">
+<gui name="Konqueror" version="69">
 <MenuBar>
  <Menu name="file" noMerge="1"><text>&amp;File</text>
   <Action name="new_window"/>
@@ -109,6 +109,7 @@
 <ToolBar fullWidth="true" iconText="icononly" name="locationToolBar" \
newline="false"><text>Location Toolbar</text>  <Action name="toolbar_url_combo" />
   <Action name="go_url" />
+  <Action name="konq_logo" />
 </ToolBar>
 <ToolBar noEdit="true" iconText="icontextright" fullWidth="true" \
name="bookmarkToolBar" iconSize="16" newline="true"><text>Bookmark Toolbar</text>  \
</ToolBar>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic