~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kicker/extensions/sidebar/sidebarextension.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                               sidebarextension.cpp
 
3
                             -------------------
 
4
    begin                : Sun July 20 16:00:00 CEST 2003
 
5
    copyright            : (C) 2003 Joseph Wenninger
 
6
    email                : jowenn@kde.org
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
#include "sidebarextension.h"
 
18
#include "sidebarextension.moc"
 
19
#include <kdebug.h>
 
20
#include <kmessagebox.h>
 
21
#include <kglobal.h>
 
22
#include <klocale.h>
 
23
#include <kparts/part.h>
 
24
#include <kparts/componentfactory.h>
 
25
#include <QLayout>
 
26
#include <QMouseEvent>
 
27
#include <QFrame>
 
28
#include <QHBoxLayout>
 
29
#include <QEvent>
 
30
//#include <konq_historymgr.h>
 
31
#include <krun.h>
 
32
#include <kurl.h>
 
33
#include <kvbox.h>
 
34
#include <QCursor>
 
35
 
 
36
extern "C"
 
37
{
 
38
   KDE_EXPORT KPanelExtension *init( QWidget *parent, const QString& configFile )
 
39
   {
 
40
      KGlobal::locale()->insertCatalog("kickersidebarextension");
 
41
      KGlobal::locale()->insertCatalog("konqueror");
 
42
      return new SidebarExtension(configFile, 0, parent);
 
43
   }
 
44
}
 
45
 
 
46
SidebarExtension::SidebarExtension(const QString& configFile,
 
47
                                   int actions,
 
48
                                   QWidget *parent)
 
49
   : KPanelExtension(configFile, actions, parent),
 
50
     m_resizing(false),
 
51
     m_expandedSize(200)
 
52
{
 
53
    // DF: what was this for?
 
54
    //new KonqHistoryManager(0);
 
55
    m_layout=new QHBoxLayout(this);
 
56
    m_layout->activate();
 
57
    m_sbWrapper=new KVBox(this);
 
58
    QStringList args;
 
59
    args << "universal";
 
60
    KParts::ReadOnlyPart *p=KParts::ComponentFactory::createPartInstanceFromLibrary<KParts::ReadOnlyPart>(
 
61
                                                 "konq_sidebar",
 
62
                                                 m_sbWrapper,
 
63
                                                 this,
 
64
                                                 args);
 
65
 
 
66
    KParts::BrowserExtension *be=KParts::BrowserExtension::childObject(p);
 
67
    if (be) {
 
68
        connect(be,SIGNAL(openUrlRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments & )),
 
69
                        this,SLOT(openUrlRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments & )));
 
70
        connect(be,SIGNAL(createNewWindow( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments & )),
 
71
                        this,SLOT(openUrlRequest( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments & )));
 
72
 
 
73
    }
 
74
 
 
75
    m_resizeHandle=new QFrame(this);
 
76
    m_resizeHandle->setFrameShape(QFrame::Panel);
 
77
    m_resizeHandle->setFrameShadow(QFrame::Raised);
 
78
    m_resizeHandle->setFixedWidth(6);
 
79
    m_resizeHandle->setCursor(QCursor(Qt::SizeHorCursor));
 
80
    connect(p->widget(),SIGNAL(panelHasBeenExpanded(bool)),this,SLOT(needLayoutUpdate(bool)));
 
81
    needLayoutUpdate(false);
 
82
    m_resizeHandle->installEventFilter(this);
 
83
    m_resizeHandle->setMouseTracking(true);
 
84
//   l->add(p->widget());
 
85
//   p->widget()->show();
 
86
//   l->activate();
 
87
 
 
88
}
 
89
 
 
90
void SidebarExtension::needLayoutUpdate(bool exp) {
 
91
        setReserveStrut(!exp); // only reserve a strut when we are collapsed
 
92
        if (exp) {
 
93
                m_currentWidth=m_expandedSize;
 
94
                m_resizeHandle->show();
 
95
                raise();
 
96
        } else {
 
97
                m_currentWidth=24;
 
98
                m_resizeHandle->hide();
 
99
        }
 
100
        topLevelWidget()->setFixedWidth(m_currentWidth);
 
101
        emit updateLayout();
 
102
}
 
103
 
 
104
void SidebarExtension::openUrlRequest( const KUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments & ) {
 
105
 
 
106
        KRun::runCommand("kfmclient openURL \""+url.prettyUrl()+"\"", "kfmclient", "konqueror", topLevelWidget());
 
107
}
 
108
 
 
109
 
 
110
SidebarExtension::~SidebarExtension()
 
111
{
 
112
      KGlobal::locale()->removeCatalog("kickersidebarextension");
 
113
      KGlobal::locale()->removeCatalog("konqueror");
 
114
}
 
115
 
 
116
bool SidebarExtension::eventFilter( QObject *, QEvent *e ) {
 
117
        if (e->type()==QEvent::MouseButtonPress) {
 
118
                m_resizing=true;
 
119
                m_x=((QMouseEvent*)e)->globalX();
 
120
                return true;
 
121
        } else if (e->type()==QEvent::MouseButtonRelease) {
 
122
                m_resizing=false;
 
123
                m_expandedSize=topLevelWidget()->width();
 
124
                needLayoutUpdate(true);
 
125
                return true;
 
126
        } else if (e->type()==QEvent::MouseMove) {
 
127
                if (m_resizing) {
 
128
                        Plasma::Position p = position();
 
129
                        if (p==Plasma::Left) {
 
130
                                int diff=((QMouseEvent*)e)->globalX()-m_x;
 
131
                                        if (abs(diff)>3) {
 
132
                                                topLevelWidget()->setFixedWidth(topLevelWidget()->width()+diff);
 
133
                                                m_x=((QMouseEvent*)e)->globalX();
 
134
                                        }
 
135
                        } else if (p==Plasma::Right) {
 
136
                                int diff=((QMouseEvent*)e)->globalX()-m_x;
 
137
                                        if (abs(diff)>3) {
 
138
                                                topLevelWidget()->setFixedWidth(topLevelWidget()->width()-diff);
 
139
                                                topLevelWidget()->move(topLevelWidget()->x()+diff,topLevelWidget()->y());
 
140
                                                m_x=((QMouseEvent*)e)->globalX();
 
141
                                        }
 
142
                        }
 
143
                        return true;
 
144
                }
 
145
        }
 
146
        return false;
 
147
}
 
148
 
 
149
Plasma::Position SidebarExtension::preferedPosition() const {
 
150
        kDebug()<<"SidebarExtension::preferedPosition()***************";
 
151
        return Plasma::Left;
 
152
}
 
153
 
 
154
QSize SidebarExtension::sizeHint(Plasma::Position, QSize maxSize ) const
 
155
{
 
156
        return QSize(m_currentWidth,maxSize.height());
 
157
}
 
158
 
 
159
void SidebarExtension::positionChange( Plasma::Position  position ) {
 
160
        if (position == Plasma::Right) {
 
161
                m_layout->remove(m_sbWrapper);
 
162
                m_layout->remove(m_resizeHandle);
 
163
 
 
164
                m_layout->addWidget(m_resizeHandle);
 
165
                m_layout->addWidget(m_sbWrapper);
 
166
        } else  if (position == Plasma::Left) {
 
167
                m_layout->remove(m_sbWrapper);
 
168
                m_layout->remove(m_resizeHandle);
 
169
 
 
170
                m_layout->addWidget(m_sbWrapper);
 
171
                m_layout->addWidget(m_resizeHandle);
 
172
 
 
173
        }
 
174
 
 
175
}
 
176
 
 
177
void SidebarExtension::about()
 
178
{
 
179
}
 
180
 
 
181
void SidebarExtension::preferences()
 
182
{
 
183
}
 
184