~ubuntu-branches/ubuntu/hoary/kvirc/hoary

« back to all changes in this revision

Viewing changes to src/kvirc/script/kvi_script_toolbar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Robin Verduijn
  • Date: 2004-12-14 15:32:19 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041214153219-fdink3gyp2s20b6g
Tags: 2:2.1.3.1-2
* Change Recommends on xmms to a Suggests.
* Rebuild against KDE 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =============================================================================
 
2
//
 
3
//   This file is part of the KVIrc IRC client distribution
 
4
//   Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
 
5
//
 
6
//   This program is FREE software. You can redistribute it and/or
 
7
//   modify it under the terms of the GNU General Public License
 
8
//   as published by the Free Software Foundation; either version 2
 
9
//   of the License, or (at your opinion) 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.
 
14
//   See the GNU 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. If not, write to the Free Software Foundation,
 
18
//   Inc, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
//
 
20
// =============================================================================
 
21
 
 
22
#define _KVI_DEBUG_CHECK_RANGE_
 
23
#define _KVI_DEBUG_CLASS_NAME_ "KviScriptToolBar"
 
24
 
 
25
#include "kvi_error.h"
 
26
#include "kvi_frame.h"
 
27
#include "kvi_script_objectclassdefinition.h"
 
28
#include "kvi_script_objectcontroller.h"
 
29
#include "kvi_script_toolbar.h"
 
30
#include "kvi_toolbar.h"
 
31
 
 
32
/*
 
33
        @class: toolbar
 
34
        @short:
 
35
                A toolbar class
 
36
        @inherits:
 
37
                [class]object[/class]<br>
 
38
                [class]widget[/class]
 
39
        @functions:
 
40
                !fn: $dock(&lt;docksite&gt;)
 
41
                Docks the toolbar to one of the sides of the main window.<br>
 
42
                Returns 1 if the operation was sucessfull or 0 if the toolbar is not
 
43
                a children or a KVIrc main window and thus cannot be docked successfully.<br>
 
44
                The &lt;docksite&gt; can be one of :<br>
 
45
                top, left, right, bottom, minimized.<br>
 
46
 
 
47
                !fn: $setDockEnabled(&lt;docksite&gt;, &lt;bEnabled&gt;)
 
48
                Enables or disables a specific docksite for this toolbar.<br>
 
49
                The &lt;docksite&gt; can be one of :<br>
 
50
                top, left, right, bottom, minimized.<br>
 
51
                &lt;bEnabled&gt; can be '1' to enable the docksite and '0' to disable it.<br>
 
52
                Returns 1 if the operation was sucessfull or 0 if the toolbar is not
 
53
                a children or a KVIrc main window and thus cannot be docked successfully.<br>
 
54
 
 
55
        @description:
 
56
                A toolbar widget.<br>
 
57
                It is used mainly with the [class]toolbutton[/class] objects.<br>
 
58
                If the parent of the toolbar is a non-widget object ([fnc]$root[/fnc] for example),
 
59
                the toolbar will be owned by the main KVIrc window.<br>
 
60
                In that case, it will be possible to dock it to one of the four sides
 
61
                of the window and drag it around.<br>
 
62
 
 
63
        @examples:
 
64
 
 
65
        @seealso:
 
66
                class [class]object[/class], <br>
 
67
                class [class]widget[/class], <br>
 
68
                class [class]toolbutton[/class], <br>
 
69
                <a href="syntax_objects.kvihelp">Objects documentation</a><br>
 
70
*/
 
71
 
 
72
/**
 
73
 * TOOLBAR class
 
74
 */
 
75
void KviScriptToolBar::initializeClassDefinition(KviScriptObjectClassDefinition *d)
 
76
{
 
77
        d->addBuiltinFunction("dock",           (scriptObjectFunction) &KviScriptToolBar::builtinFunction_DOCK);
 
78
        d->addBuiltinFunction("setDockEnabled", (scriptObjectFunction) &KviScriptToolBar::builtinFunction_SETDOCKENABLED);
 
79
}
 
80
 
 
81
KviScriptToolBar::KviScriptToolBar(
 
82
        KviScriptObjectController *cntrl, KviScriptObject *p, const char *name, KviScriptObjectClassDefinition *pDef)
 
83
        : KviScriptWidget(cntrl, p, name, pDef)
 
84
{
 
85
        // Nothing here
 
86
}
 
87
 
 
88
KviScriptToolBar::~KviScriptToolBar()
 
89
{
 
90
        // Nothing here
 
91
}
 
92
 
 
93
bool KviScriptToolBar::init(QPtrList<KviStr> *params)
 
94
{
 
95
        if( parent() ) {
 
96
                if( parent()->inherits("KviScriptWidget") ) {
 
97
                        m_pWidget = new KviToolBar(
 
98
                                name(), controller()->mainFrame(), ((KviScriptWidget *) parent())->m_pWidget, Qt::DockTop, false, name()
 
99
                        );
 
100
                }
 
101
        }
 
102
        if( !m_pWidget )
 
103
                m_pWidget = new KviToolBar(name(), controller()->mainFrame(), controller()->mainFrame(), Qt::DockTop, false, name());
 
104
        m_bAutoDestroyControlledWidget = true;
 
105
        m_pWidget->installEventFilter(this);
 
106
        connect(m_pWidget, SIGNAL(destroyed()), this, SLOT(widgetDestroyed()));
 
107
        return true;
 
108
}
 
109
 
 
110
Qt::Dock KviScriptToolBar::getDockId(const char *str)
 
111
{
 
112
        if( !str ) return DockMinimized;
 
113
 
 
114
        if( kvi_strEqualCI(str, "top") )    return DockTop;
 
115
        if( kvi_strEqualCI(str, "bottom") ) return DockBottom;
 
116
        if( kvi_strEqualCI(str, "left") )   return DockLeft;
 
117
        if( kvi_strEqualCI(str, "right") )  return DockRight;
 
118
        return DockMinimized;
 
119
}
 
120
 
 
121
int KviScriptToolBar::builtinFunction_DOCK(QPtrList<KviStr> *params, KviStr &buffer)
 
122
{
 
123
        if( parent()->inherits("KviScriptWidget") ) {
 
124
                // Cannot dock
 
125
                buffer.append('0');
 
126
                return KVI_ERROR_Success;
 
127
        }
 
128
        if( params ) {
 
129
                KviStr *pS = params->first();
 
130
                if( pS ) {
 
131
                        KviMainWindow *w = (KviMainWindow *) ((KviToolBar *) m_pWidget)->mainWindow();
 
132
                        if( w ) {
 
133
                                w->moveToolBar((KviToolBar *) m_pWidget, getDockId(pS->ptr()));
 
134
                                buffer.append('1');
 
135
                        } else {
 
136
                                // Cannot dock
 
137
                                buffer.append('0');
 
138
                        }
 
139
                        return KVI_ERROR_Success;
 
140
                }
 
141
        }
 
142
        return KVI_ERROR_MissingParameter;
 
143
}
 
144
 
 
145
int KviScriptToolBar::builtinFunction_SETDOCKENABLED(QPtrList<KviStr> *params, KviStr &buffer)
 
146
{
 
147
        if( parent()->inherits("KviScriptWidget") ) {
 
148
                // Cannot dock
 
149
                buffer.append('0');
 
150
                return KVI_ERROR_Success;
 
151
        }
 
152
        if( params ) {
 
153
                KviStr *pS = params->first();
 
154
                if( pS ) {
 
155
                        KviStr *pS2 = params->next();
 
156
                        bool bEnable = true;
 
157
                        if( pS2 ) {
 
158
                                if( kvi_strEqualCI(pS2->ptr(), "0") )
 
159
                                        bEnable = false;
 
160
                        }
 
161
                        KviMainWindow *w = (KviMainWindow *) ((KviToolBar *) m_pWidget)->mainWindow();
 
162
                        if( w ) {
 
163
                                w->setDockEnabled((KviToolBar *) m_pWidget, getDockId(pS->ptr()), bEnable);
 
164
                                buffer.append('1');
 
165
                        } else {
 
166
                                // Cannot dock
 
167
                                buffer.append('0');
 
168
                        }
 
169
                        return KVI_ERROR_Success;
 
170
                }
 
171
        }
 
172
        return KVI_ERROR_MissingParameter;
 
173
}
 
174
 
 
175
#include "m_kvi_script_toolbar.moc"