~ubuntu-branches/ubuntu/utopic/kdebase/utopic

« back to all changes in this revision

Viewing changes to .pc/kubuntu_23_konqueror_spinner_in_toolbar.diff/apps/konqueror/src/konqanimatedlogo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-25 16:00:47 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20101125160047-bsycodsp50o8su5s
Tags: 4:4.5.80-0ubuntu1
* New upstream beta release
* Drop kubuntu_06_simple_aboutpage.diff, didn't apply and no point
  keeping a distro patch to an app we don't ship by default
* Drop kubuntu_23_konqueror_spinner_in_toolbar.diff now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
   This file is part of the KDE project
3
 
   Copyright (C) 2008 David Faure <faure@kde.org>
4
 
   Copyright (C) 2009 Christoph Feck <christoph@maxiom.de>
5
 
 
6
 
   This program is free software; you can redistribute it and/or
7
 
   modify it under the terms of the GNU General Public
8
 
   License as published by the Free Software Foundation; either
9
 
   version 2 of the License, or (at your option) any later version.
10
 
 
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
    General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program; see the file COPYING.  If not, write to
18
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
 
   Boston, MA 02110-1301, USA.
20
 
*/
21
 
 
22
 
#include "konqanimatedlogo_p.h"
23
 
 
24
 
#include <KDE/KIconLoader>
25
 
 
26
 
#include <QtCore/QEvent>
27
 
#include <QtGui/QMenuBar>
28
 
#include <QtGui/QStyle>
29
 
#include <QtGui/QStyleOptionMenuItem>
30
 
 
31
 
KonqAnimatedLogo::KonqAnimatedLogo(QWidget *parent)
32
 
    : KAnimatedButton(parent)
33
 
{
34
 
    setAutoRaise(true);
35
 
    setFocusPolicy(Qt::NoFocus);
36
 
    setToolButtonStyle(Qt::ToolButtonIconOnly);
37
 
    setAnimatedLogoSize(maxThrobberHeight());
38
 
    if (qobject_cast<QMenuBar *>(parent))
39
 
        parent->installEventFilter(this);
40
 
}
41
 
 
42
 
KonqAnimatedLogo::~KonqAnimatedLogo()
43
 
{
44
 
    if (parentWidget())
45
 
        parentWidget()->removeEventFilter(this);
46
 
}
47
 
 
48
 
QSize KonqAnimatedLogo::sizeHint() const
49
 
{
50
 
    return m_size;
51
 
}
52
 
 
53
 
void KonqAnimatedLogo::changeEvent(QEvent *event)
54
 
{
55
 
    KAnimatedButton::changeEvent(event);
56
 
    if (event->type() == QEvent::ParentAboutToChange) {
57
 
        if (parentWidget())
58
 
            parentWidget()->removeEventFilter(this);
59
 
    } else if (event->type() == QEvent::ParentChange) {
60
 
        if (qobject_cast<QMenuBar *>(parentWidget()))
61
 
            parentWidget()->installEventFilter(this);
62
 
    }
63
 
}
64
 
 
65
 
bool KonqAnimatedLogo::eventFilter(QObject *watched, QEvent *event)
66
 
{
67
 
    if (qobject_cast<QWidget *>(watched) == parentWidget()) {
68
 
        if (event->type() == QEvent::StyleChange || event->type() == QEvent::FontChange
69
 
            || event->type() == QEvent::ApplicationFontChange) {
70
 
            // make sure the logo is resized before the menu bar gets the
71
 
            // font change event
72
 
            setAnimatedLogoSize(maxThrobberHeight());
73
 
        }
74
 
    }
75
 
    return KAnimatedButton::eventFilter(watched, event);
76
 
}
77
 
 
78
 
int KonqAnimatedLogo::maxThrobberHeight()
79
 
{
80
 
    QMenuBar *menuBar = qobject_cast<QMenuBar *>(parentWidget());
81
 
    if (!menuBar)
82
 
        return 22;
83
 
 
84
 
    // This comes from QMenuBar::sizeHint and QMenuBarPrivate::calcActionRects
85
 
    const QFontMetrics fm = menuBar->fontMetrics();
86
 
    QSize sz(100, fm.height());
87
 
    //let the style modify the above size..
88
 
    QStyleOptionMenuItem opt;
89
 
    opt.fontMetrics = fm;
90
 
    opt.state = QStyle::State_Enabled;
91
 
    opt.menuRect = menuBar->rect();
92
 
    opt.text = "dummy";
93
 
    sz = menuBar->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, menuBar);
94
 
    //kDebug() << "maxThrobberHeight=" << sz.height();
95
 
    return sz.height();
96
 
}
97
 
 
98
 
void KonqAnimatedLogo::setAnimatedLogoSize(int buttonHeight)
99
 
{
100
 
    // This gives the best results: we force a bigger icon size onto the style, and it'll just have to eat up its margin.
101
 
    // So we don't need to ask sizeFromContents at all.
102
 
    int iconSize = buttonHeight - 4;
103
 
#if 0
104
 
    QStyleOptionToolButton opt;
105
 
    opt.initFrom(m_paAnimatedLogo);
106
 
    const QSize finalSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, opt.iconSize, m_paAnimatedLogo);
107
 
    //kDebug() << "throbberIconSize=" << buttonHeight << "-" << finalSize.height() - opt.iconSize.height();
108
 
    int iconSize = buttonHeight - (finalSize.height() - opt.iconSize.height());
109
 
#endif
110
 
 
111
 
    m_size = QSize(buttonHeight, buttonHeight);
112
 
    setFixedSize(m_size);
113
 
 
114
 
    //kDebug() << "buttonHeight=" << buttonHeight << "max iconSize=" << iconSize;
115
 
    if ( iconSize < KIconLoader::SizeSmallMedium )
116
 
        iconSize = KIconLoader::SizeSmall;
117
 
    else if ( iconSize < KIconLoader::SizeMedium  )
118
 
        iconSize = KIconLoader::SizeSmallMedium;
119
 
    else if ( iconSize < KIconLoader::SizeLarge )
120
 
        iconSize = KIconLoader::SizeMedium ;
121
 
    else
122
 
        iconSize = KIconLoader::SizeLarge;
123
 
    //kDebug() << "final iconSize=" << iconSize;
124
 
    if (iconDimensions() != iconSize) {
125
 
        setIconSize(QSize(iconSize, iconSize));
126
 
        if (!icons().isEmpty()) {
127
 
            updateIcons();
128
 
        }
129
 
    }
130
 
}
131
 
 
132
 
#include "konqanimatedlogo_p.moc"