~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kexi/core/KexiView.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2004-2007 Jarosław Staniek <staniek@kde.org>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "KexiView.h"
 
21
#include "KexiMainWindowIface.h"
 
22
 
 
23
#include "KexiWindow.h"
 
24
#include "kexiproject.h"
 
25
#include <koproperty/Set.h>
 
26
 
 
27
#include <kexidb/connection.h>
 
28
#include <kexidb/utils.h>
 
29
#include <kexiutils/utils.h>
 
30
#include <kexiutils/SmallToolButton.h>
 
31
#include <kexiutils/FlowLayout.h>
 
32
 
 
33
#include <KDebug>
 
34
#include <KDialog>
 
35
#include <KActionCollection>
 
36
#include <QEvent>
 
37
#include <QCloseEvent>
 
38
#include <QApplication>
 
39
#include <QVBoxLayout>
 
40
#include <QLabel>
 
41
 
 
42
/*class KexiToggleViewModeAction::Private
 
43
{
 
44
  public:
 
45
    Private()
 
46
    {
 
47
    }
 
48
  Kexi::ViewMode mode;
 
49
};*/
 
50
 
 
51
KexiToggleViewModeAction::KexiToggleViewModeAction(
 
52
    Kexi::ViewMode mode, QObject* parent)//, QObject* receiver, const char* slot)
 
53
        : KAction(
 
54
            KIcon(Kexi::iconNameForViewMode(mode)),
 
55
            Kexi::nameForViewMode(mode, true/*withAmpersand*/),
 
56
            parent)
 
57
// , d( new Private )
 
58
{
 
59
// d->mode = mode;
 
60
// connect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled(bool)));
 
61
// if (receiver && slot)
 
62
//  connect(this, SIGNAL(switchedTo(Kexi::ViewMode)), receiver, slot);
 
63
    setCheckable(true);
 
64
    if (mode == Kexi::DataViewMode) {
 
65
        setObjectName("view_data_mode");
 
66
        setToolTip(i18n("Switch to data view"));
 
67
        setWhatsThis(i18n("Switches to data view."));
 
68
    } else if (mode == Kexi::DesignViewMode) {
 
69
        setObjectName("view_design_mode");
 
70
        setToolTip(i18n("Switch to design view"));
 
71
        setWhatsThis(i18n("Switches to design view."));
 
72
    } else if (mode == Kexi::TextViewMode) {
 
73
        setObjectName("view_text_mode");
 
74
        setToolTip(i18n("Switch to text view"));
 
75
        setWhatsThis(i18n("Switches to text view."));
 
76
    } else {
 
77
        kWarning() << "KexiToggleViewModeAction: invalid mode " << mode;
 
78
    }
 
79
}
 
80
 
 
81
/*
 
82
void KexiToggleViewModeAction::slotToggled(bool checked)
 
83
{
 
84
  if (!checked)
 
85
    return;
 
86
  emit switchedTo(d->mode);
 
87
}*/
 
88
 
 
89
//-------------------------
 
90
 
 
91
class KexiView::Private
 
92
{
 
93
public:
 
94
    Private()
 
95
    //: viewModeGroup(0)
 
96
            : viewWidget(0)
 
97
            , parentView(0)
 
98
            , newlyAssignedID(-1)
 
99
            , viewMode(Kexi::NoViewMode) //unknown!
 
100
            , isDirty(false)
 
101
            , slotSwitchToViewModeInternalEnabled(true)
 
102
            , sortedProperties(false)
 
103
            , recentResultOfSwitchToViewModeInternal(true) {
 
104
    }
 
105
 
 
106
    ~Private() {
 
107
        /*   qDeleteAll(viewActions); */
 
108
        /*   foreach(KAction* action, viewActions) {
 
109
                //only delete action if it is not shared (otherwise, window itself will delete it)
 
110
                if (!window->sharedViewAction(action->name()))
 
111
                  delete action;
 
112
              }*/
 
113
    }
 
114
 
 
115
    void toggleViewModeButtonBack(Kexi::ViewMode mode) {
 
116
        QAction *a = toggleViewModeActions.value(mode);
 
117
        if (a) {
 
118
            slotSwitchToViewModeInternalEnabled = false;
 
119
            toggleViewModeActions.value(mode)->blockSignals(true);
 
120
            toggleViewModeButtons.value(mode)->blockSignals(true);
 
121
            toggleViewModeButtons.value(mode)->setChecked(viewMode == mode);
 
122
            toggleViewModeActions.value(mode)->blockSignals(false);
 
123
            toggleViewModeButtons.value(mode)->blockSignals(false);
 
124
            //a->setChecked(viewMode == mode);
 
125
            slotSwitchToViewModeInternalEnabled = true;
 
126
        }
 
127
    }
 
128
 
 
129
    QVBoxLayout* mainLyr;
 
130
    QWidget *topBarHWidget;
 
131
    KexiFlowLayout *topBarLyr;
 
132
    //QActionGroup* viewModeGroup;
 
133
    QHash<Kexi::ViewMode, QAction*> toggleViewModeActions;
 
134
    QHash<Kexi::ViewMode, KexiSmallToolButton*> toggleViewModeButtons;
 
135
 
 
136
    KexiSmallToolButton* saveDesignButton;
 
137
//  KexiToolBarSeparator* saveDesignButtonSeparator;
 
138
 
 
139
    QString defaultIconName;
 
140
    KexiWindow *window;
 
141
    QWidget *viewWidget;
 
142
    KexiView *parentView;
 
143
 
 
144
    QPointer<QWidget> lastFocusedChildBeforeFocusOut;
 
145
 
 
146
    /*! Member set to newly assigned object's ID in storeNewData()
 
147
     and used in storeDataBlock(). This is needed because usually,
 
148
     storeDataBlock() can be called from storeNewData() and in this case
 
149
     window has not yet assigned valid identifier (it has just negative temp. number).
 
150
     \sa KexiWindow::id()
 
151
     */
 
152
    int newlyAssignedID;
 
153
 
 
154
    /*! Mode for this view. Initialized by KexiWindow::switchToViewMode().
 
155
     Can be useful when single class is used for more than one view (e.g. KexiDBForm). */
 
156
    Kexi::ViewMode viewMode;
 
157
 
 
158
    QList<KexiView*> children;
 
159
 
 
160
    /*! View-level actions (not shared), owned by the view. */
 
161
    QList<QAction*> viewActions;
 
162
    QHash<QByteArray, QAction*> viewActionsHash;
 
163
 
 
164
    bool isDirty;
 
165
 
 
166
    //! Used in slotSwitchToViewModeInternal() to disabling it
 
167
    bool slotSwitchToViewModeInternalEnabled;
 
168
 
 
169
    bool sortedProperties;
 
170
 
 
171
    //! Used in slotSwitchToViewModeInternal() to disabling d->window->switchToViewModeInternal(mode) call.
 
172
    //! Needed because there is another slotSwitchToViewModeInternal() calls if d->window->switchToViewModeInternal(mode)
 
173
    //! did not succeed, so for the second time we block this call.
 
174
    tristate recentResultOfSwitchToViewModeInternal;
 
175
};
 
176
 
 
177
//----------------------------------------------------------
 
178
 
 
179
KexiView::KexiView(QWidget *parent)
 
180
        : QWidget(parent)
 
181
        , KexiActionProxy(this)
 
182
        , d(new Private())
 
183
{
 
184
    QWidget *wi = this;
 
185
    while ((wi = wi->parentWidget()) && !wi->inherits("KexiWindow"))
 
186
        ;
 
187
    d->window = (wi && wi->inherits("KexiWindow")) ? static_cast<KexiWindow*>(wi) : 0;
 
188
    if (d->window) {
 
189
        //init view mode number for this view (obtained from window where this view is created)
 
190
        if (d->window->supportsViewMode(d->window->creatingViewsMode()))
 
191
            d->viewMode = d->window->creatingViewsMode();
 
192
    }
 
193
    setObjectName(
 
194
        QString("%1_for_%2_object")
 
195
        .arg(Kexi::nameForViewMode(d->viewMode).replace(" ", "_"))
 
196
        .arg(d->window ? d->window->partItem()->name() : QString("??")));
 
197
 
 
198
    installEventFilter(this);
 
199
 
 
200
    // QLayout *l = layout(); -- FIXME: Not used?
 
201
    d->mainLyr = new QVBoxLayout(this);
 
202
    d->mainLyr->setContentsMargins(0, KDialog::marginHint() / 3, 0, 0);
 
203
 
 
204
    if (parentWidget()->inherits("KexiWindow")) {
 
205
        d->topBarHWidget = new QWidget(this);
 
206
        d->topBarHWidget->setFont(KexiUtils::smallFont());
 
207
        d->mainLyr->addWidget(d->topBarHWidget);
 
208
        QHBoxLayout *topBarHLyr = new QHBoxLayout(d->topBarHWidget); //needed unless KexiFlowLayout properly handles contents margins
 
209
        topBarHLyr->setContentsMargins(0, 0, 0, 0);
 
210
        topBarHLyr->addSpacing(KDialog::marginHint() / 2);
 
211
        d->topBarLyr = new KexiFlowLayout(topBarHLyr, KDialog::marginHint() / 2, 2);
 
212
 
 
213
        const bool userMode = KexiMainWindowIface::global()->userMode();
 
214
 
 
215
        if (userMode
 
216
                || d->window->supportedViewModes() == Kexi::DataViewMode
 
217
                || d->window->supportedViewModes() == Kexi::DesignViewMode
 
218
                || d->window->supportedViewModes() == Kexi::TextViewMode) {
 
219
            // nothing to do: only single view mode supported
 
220
        } else {
 
221
            if (parentWidget()->inherits("KexiWindow")) {
 
222
                createViewModeToggleButtons();
 
223
            }
 
224
        }
 
225
 
 
226
        QAction * a;
 
227
        if (d->viewMode == Kexi::DesignViewMode || d->viewMode == Kexi::TextViewMode) {
 
228
            d->topBarLyr->addWidget(new KexiToolBarSeparator(d->topBarHWidget));
 
229
 
 
230
            a = sharedAction("project_save");
 
231
            d->saveDesignButton = new KexiSmallToolButton(a, d->topBarHWidget);
 
232
            d->saveDesignButton->setText(i18n("Save"));
 
233
            d->saveDesignButton->setToolTip(i18n("Save current design"));
 
234
            d->saveDesignButton->setWhatsThis(i18n("Saves changes made to the current design."));
 
235
            d->topBarLyr->addWidget(d->saveDesignButton);
 
236
//   d->topBarLyr->addWidget( d->saveDesignButtonSeparator = new KexiToolBarSeparator(d->topBarHWidget));
 
237
        } else {
 
238
            d->saveDesignButton = 0;
 
239
        }
 
240
    } else {
 
241
        // no toolbar
 
242
        d->saveDesignButton = 0;
 
243
        d->topBarHWidget = 0;
 
244
        d->topBarLyr = 0;
 
245
    }
 
246
}
 
247
 
 
248
KexiView::~KexiView()
 
249
{
 
250
    delete d;
 
251
}
 
252
 
 
253
KexiWindow* KexiView::window() const
 
254
{
 
255
    return d->window;
 
256
}
 
257
 
 
258
bool KexiView::isDirty() const
 
259
{
 
260
    return d->isDirty;
 
261
}
 
262
 
 
263
Kexi::ViewMode KexiView::viewMode() const
 
264
{
 
265
    return d->viewMode;
 
266
}
 
267
 
 
268
KexiPart::Part* KexiView::part() const
 
269
{
 
270
    return d->window ? d->window->part() : 0;
 
271
}
 
272
 
 
273
tristate KexiView::beforeSwitchTo(Kexi::ViewMode mode, bool & dontStore)
 
274
{
 
275
    Q_UNUSED(mode);
 
276
    Q_UNUSED(dontStore);
 
277
    return true;
 
278
}
 
279
 
 
280
tristate KexiView::afterSwitchFrom(Kexi::ViewMode mode)
 
281
{
 
282
    Q_UNUSED(mode);
 
283
    return true;
 
284
}
 
285
 
 
286
QSize KexiView::preferredSizeHint(const QSize& otherSize)
 
287
{
 
288
#ifdef __GNUC__
 
289
#warning KexiView::preferredSizeHint()
 
290
#else
 
291
#pragma WARNING( KexiView::preferredSizeHint() )
 
292
#endif
 
293
#if 0 //todo
 
294
    KexiWindow* w = d->window;
 
295
    if (dlg && dlg->mdiParent()) {
 
296
        QRect r = dlg->mdiParent()->mdiAreaContentsRect();
 
297
        return otherSize.boundedTo(QSize(
 
298
                                       r.width() - 10,
 
299
                                       r.height() - dlg->mdiParent()->captionHeight() - dlg->pos().y() - 10
 
300
                                   ));
 
301
    }
 
302
#endif
 
303
    return otherSize;
 
304
}
 
305
 
 
306
void KexiView::closeEvent(QCloseEvent * e)
 
307
{
 
308
    bool cancel = false;
 
309
    emit closing(cancel);
 
310
    if (cancel) {
 
311
        e->ignore();
 
312
        return;
 
313
    }
 
314
    QWidget::closeEvent(e);
 
315
}
 
316
 
 
317
KoProperty::Set *KexiView::propertySet()
 
318
{
 
319
    return 0;
 
320
}
 
321
 
 
322
void KexiView::propertySetSwitched()
 
323
{
 
324
    if (window()) {
 
325
        KexiMainWindowIface::global()->propertySetSwitched(window(), false/*force*/, 
 
326
            true/*preservePrevSelection*/, d->sortedProperties);
 
327
    }
 
328
}
 
329
 
 
330
void KexiView::propertySetReloaded(bool preservePrevSelection,
 
331
                                   const QByteArray& propertyToSelect)
 
332
{
 
333
    if (window())
 
334
        KexiMainWindowIface::global()->propertySetSwitched(
 
335
            window(), true, preservePrevSelection, d->sortedProperties, propertyToSelect);
 
336
}
 
337
 
 
338
void KexiView::setDirty(bool set)
 
339
{
 
340
    const bool changed = (d->isDirty != set);
 
341
    d->isDirty = set;
 
342
    d->isDirty = isDirty();
 
343
    if (d->saveDesignButton)
 
344
        d->saveDesignButton->setEnabled(d->isDirty);
 
345
    if (d->parentView) {
 
346
        d->parentView->setDirty(d->isDirty);
 
347
    } else {
 
348
        if (changed && d->window)
 
349
            d->window->dirtyChanged(this);
 
350
    }
 
351
}
 
352
 
 
353
/*bool KexiView::saveData()
 
354
{
 
355
  //TODO....
 
356
 
 
357
  //finally:
 
358
  setDirty(false);
 
359
  return true;
 
360
}*/
 
361
 
 
362
KexiDB::SchemaData* KexiView::storeNewData(const KexiDB::SchemaData& sdata, bool & /*cancel*/)
 
363
{
 
364
    KexiDB::SchemaData *new_schema = new KexiDB::SchemaData();
 
365
    *new_schema = sdata;
 
366
 
 
367
    if (!KexiMainWindowIface::global()->project()->dbConnection()
 
368
            ->storeObjectSchemaData(*new_schema, true)) {
 
369
        delete new_schema;
 
370
        new_schema = 0;
 
371
    }
 
372
    d->newlyAssignedID = new_schema->id();
 
373
    return new_schema;
 
374
}
 
375
 
 
376
tristate KexiView::storeData(bool dontAsk)
 
377
{
 
378
    Q_UNUSED(dontAsk);
 
379
    if (!d->window || !d->window->schemaData())
 
380
        return false;
 
381
    if (!KexiMainWindowIface::global()->project()->dbConnection()
 
382
            ->storeObjectSchemaData(*d->window->schemaData(), false /*existing object*/)) {
 
383
        return false;
 
384
    }
 
385
    setDirty(false);
 
386
    return true;
 
387
}
 
388
 
 
389
bool KexiView::loadDataBlock(QString &dataString, const QString& dataID, bool canBeEmpty)
 
390
{
 
391
    if (!d->window)
 
392
        return false;
 
393
    const tristate res = KexiMainWindowIface::global()->project()->dbConnection()
 
394
                         ->loadDataBlock(d->window->id(), dataString, dataID);
 
395
    if (canBeEmpty && ~res) {
 
396
        dataString.clear();
 
397
        return true;
 
398
    }
 
399
    return res == true;
 
400
}
 
401
 
 
402
bool KexiView::storeDataBlock(const QString &dataString, const QString &dataID)
 
403
{
 
404
    if (!d->window)
 
405
        return false;
 
406
    int effectiveID;
 
407
    if (d->newlyAssignedID > 0) {//ID not yet stored within window, but we've got ID here
 
408
        effectiveID = d->newlyAssignedID;
 
409
        d->newlyAssignedID = -1;
 
410
    } else
 
411
        effectiveID = d->window->id();
 
412
 
 
413
    return effectiveID > 0
 
414
           && KexiMainWindowIface::global()->project()->dbConnection()->storeDataBlock(
 
415
               effectiveID, dataString, dataID);
 
416
}
 
417
 
 
418
bool KexiView::removeDataBlock(const QString& dataID)
 
419
{
 
420
    if (!d->window)
 
421
        return false;
 
422
    return KexiMainWindowIface::global()->project()->dbConnection()
 
423
           ->removeDataBlock(d->window->id(), dataID);
 
424
}
 
425
 
 
426
bool KexiView::eventFilter(QObject *o, QEvent *e)
 
427
{
 
428
    if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut) {// && o->inherits("QWidget")) {
 
429
//  //hp==true if currently focused widget is a child of this table view
 
430
//  const bool hp = Kexi::hasParent( static_cast<QWidget*>(o), focusWidget());
 
431
        kDebug() << "this=[" << o->metaObject()->className()
 
432
            << objectName() << "] o=[" << o->metaObject()->className() << o->objectName()
 
433
            << "] focusWidget=[" << (qApp->focusWidget() ? qApp->focusWidget()->metaObject()->className() : QString())
 
434
            << (qApp->focusWidget() ? qApp->focusWidget()->objectName() : QString()) << "] ev.type=" << e->type();
 
435
        if (KexiUtils::hasParent(this, o)) {
 
436
            if (e->type() == QEvent::FocusOut && qApp->focusWidget()
 
437
                    && !KexiUtils::hasParent(this, qApp->focusWidget())) {
 
438
                //focus out: when currently focused widget is not a parent of this view
 
439
                emit focus(false);
 
440
            } else if (e->type() == QEvent::FocusIn) {
 
441
                emit focus(true);
 
442
            }
 
443
            if (e->type() == QEvent::FocusOut) {
 
444
//    kDebug() << focusWidget()->className() << " " << focusWidget()->name();
 
445
//    kDebug() << o->className() << " " << o->name();
 
446
                KexiView *v = KexiUtils::findParent<KexiView*>(o);
 
447
                if (v) {
 
448
                    while (v->d->parentView)
 
449
                        v = v->d->parentView;
 
450
                    if (KexiUtils::hasParent(this, static_cast<QWidget*>(v->focusWidget())))
 
451
                        v->d->lastFocusedChildBeforeFocusOut = static_cast<QWidget*>(v->focusWidget());
 
452
                }
 
453
            }
 
454
 
 
455
            if (e->type() == QEvent::FocusIn && m_actionProxyParent) {
 
456
                m_actionProxyParent->m_focusedChild = this;
 
457
            }
 
458
        }
 
459
    }
 
460
    return false;
 
461
}
 
462
 
 
463
void KexiView::setViewWidget(QWidget* w, bool focusProxy)
 
464
{
 
465
    if (d->viewWidget == w)
 
466
        return;
 
467
    if (d->viewWidget) {
 
468
        d->viewWidget->removeEventFilter(this);
 
469
        d->mainLyr->removeWidget(d->viewWidget);
 
470
    }
 
471
    d->viewWidget = w;
 
472
    if (d->viewWidget) {
 
473
        //if (!d->children.contains(dynamic_cast<KexiView*>(d->viewWidget))) {
 
474
        d->viewWidget->setParent(this);
 
475
        d->mainLyr->addWidget(d->viewWidget);
 
476
        d->viewWidget->installEventFilter(this);
 
477
        //}
 
478
        if (focusProxy)
 
479
            setFocusProxy(d->viewWidget); //js: ok?
 
480
    }
 
481
}
 
482
 
 
483
void KexiView::addChildView(KexiView* childView)
 
484
{
 
485
    d->children.append(childView);
 
486
    addActionProxyChild(childView);
 
487
    childView->d->parentView = this;
 
488
 
 
489
    //childView->setParent(this);
 
490
    //d->mainLyr->addWidget(childView);
 
491
 
 
492
// if (d->parentView)
 
493
//  childView->installEventFilter(d->parentView);
 
494
    childView->installEventFilter(this);
 
495
}
 
496
 
 
497
void KexiView::setFocus()
 
498
{
 
499
    if (!d->lastFocusedChildBeforeFocusOut.isNull()) {
 
500
//  kDebug() << "FOCUS: " << d->lastFocusedChildBeforeFocusOut->className() << " " << d->lastFocusedChildBeforeFocusOut->name();
 
501
        QWidget *w = d->lastFocusedChildBeforeFocusOut;
 
502
        d->lastFocusedChildBeforeFocusOut = 0;
 
503
        w->setFocus();
 
504
    } else {
 
505
        if (hasFocus())
 
506
            setFocusInternal();
 
507
        else
 
508
            setFocusInternal();
 
509
    }
 
510
    KexiMainWindowIface::global()->invalidateSharedActions(this);
 
511
}
 
512
 
 
513
QAction* KexiView::sharedAction(const QString& action_name)
 
514
{
 
515
    if (part()) {
 
516
        KActionCollection *ac;
 
517
        if ((ac = part()->actionCollectionForMode(viewMode()))) {
 
518
            QAction* a = ac->action(action_name);
 
519
            if (a)
 
520
                return a;
 
521
        }
 
522
    }
 
523
    return KexiActionProxy::sharedAction(action_name);
 
524
}
 
525
 
 
526
void KexiView::setAvailable(const QString& action_name, bool set)
 
527
{
 
528
    if (part()) {
 
529
        KActionCollection *ac;
 
530
        QAction* a;
 
531
        if ((ac = part()->actionCollectionForMode(viewMode())) && (a = ac->action(action_name))) {
 
532
            a->setEnabled(set);
 
533
        }
 
534
    }
 
535
    KexiActionProxy::setAvailable(action_name, set);
 
536
}
 
537
 
 
538
void KexiView::updateActions(bool activated)
 
539
{
 
540
    //do nothing here
 
541
    //do the same for children :)
 
542
    foreach(KexiView* view, d->children) {
 
543
        view->updateActions(activated);
 
544
    }
 
545
}
 
546
 
 
547
void KexiView::setViewActions(const QList<QAction*>& actions)
 
548
{
 
549
    d->viewActions = actions;
 
550
    d->viewActionsHash.clear();
 
551
    foreach(QAction* action, d->viewActions) {
 
552
        d->viewActionsHash.insert(action->objectName().toLatin1(), action);
 
553
    }
 
554
}
 
555
 
 
556
QAction* KexiView::viewAction(const char* name) const
 
557
{
 
558
    return d->viewActionsHash.value(name);
 
559
}
 
560
 
 
561
QList<QAction*> KexiView::viewActions() const
 
562
{
 
563
    return d->viewActions;
 
564
}
 
565
 
 
566
void KexiView::toggleViewModeButtonBack()
 
567
{
 
568
// d->switchToViewModeInternalEnabled = false;
 
569
    d->toggleViewModeButtonBack(Kexi::DataViewMode);
 
570
    d->toggleViewModeButtonBack(Kexi::DesignViewMode);
 
571
    d->toggleViewModeButtonBack(Kexi::TextViewMode);
 
572
// d->switchToViewModeInternalEnabled = true;
 
573
}
 
574
 
 
575
void KexiView::createViewModeToggleButtons()
 
576
{
 
577
    KAction * a;
 
578
    KexiSmallToolButton *btn;
 
579
// d->viewModeGroup = new QActionGroup(this);
 
580
    QLabel *showLabel = new QLabel(i18n("Show:"), d->topBarHWidget);
 
581
    d->topBarLyr->addWidget(showLabel);
 
582
    d->topBarLyr->setAlignment(showLabel, Qt::AlignVCenter | Qt::AlignLeft);
 
583
    if (d->window->supportsViewMode(Kexi::DataViewMode)) {
 
584
        a = new KexiToggleViewModeAction(Kexi::DataViewMode, this);
 
585
//   this, SLOT(slotSwitchToViewModeInternal(Kexi::ViewMode)));
 
586
        d->toggleViewModeActions.insert(Kexi::DataViewMode, a);
 
587
//  d->viewModeGroup->addAction(a);
 
588
        btn = new KexiSmallToolButton(a, d->topBarHWidget);
 
589
        connect(btn, SIGNAL(toggled(bool)), this, SLOT(slotSwitchToDataViewModeInternal(bool)));
 
590
        d->toggleViewModeButtons.insert(Kexi::DataViewMode, btn);
 
591
        btn->setText(i18n("Data"));
 
592
        d->topBarLyr->addWidget(btn);
 
593
    }
 
594
    if (d->window->supportsViewMode(Kexi::DesignViewMode)) {
 
595
        a = new KexiToggleViewModeAction(Kexi::DesignViewMode, this);
 
596
//   this, SLOT(slotSwitchToViewModeInternal(Kexi::ViewMode)));
 
597
        d->toggleViewModeActions.insert(Kexi::DesignViewMode, a);
 
598
//  d->viewModeGroup->addAction(a);
 
599
        btn = new KexiSmallToolButton(a, d->topBarHWidget);
 
600
        connect(btn, SIGNAL(toggled(bool)), this, SLOT(slotSwitchToDesignViewModeInternal(bool)));
 
601
        d->toggleViewModeButtons.insert(Kexi::DesignViewMode, btn);
 
602
        btn->setText(i18n("Design"));
 
603
        d->topBarLyr->addWidget(btn);
 
604
    }
 
605
    if (d->window->supportsViewMode(Kexi::TextViewMode)) {
 
606
        a = new KexiToggleViewModeAction(Kexi::TextViewMode, this);
 
607
//   this, SLOT(slotSwitchToViewModeInternal(Kexi::ViewMode)));
 
608
        QString customTextViewModeCaption(d->window->internalPropertyValue("textViewModeCaption").toString());
 
609
        if (!customTextViewModeCaption.isEmpty())
 
610
            a->setText(customTextViewModeCaption);
 
611
        d->toggleViewModeActions.insert(Kexi::TextViewMode, a);
 
612
//  d->viewModeGroup->addAction(a);
 
613
        btn = new KexiSmallToolButton(a, d->topBarHWidget);
 
614
        connect(btn, SIGNAL(toggled(bool)), this, SLOT(slotSwitchToTextViewModeInternal(bool)));
 
615
        d->toggleViewModeButtons.insert(Kexi::TextViewMode, btn);
 
616
        d->topBarLyr->addWidget(btn);
 
617
    }
 
618
    toggleViewModeButtonBack();
 
619
}
 
620
 
 
621
void KexiView::slotSwitchToDataViewModeInternal(bool)
 
622
{
 
623
    slotSwitchToViewModeInternal(Kexi::DataViewMode);
 
624
}
 
625
 
 
626
void KexiView::slotSwitchToDesignViewModeInternal(bool)
 
627
{
 
628
    slotSwitchToViewModeInternal(Kexi::DesignViewMode);
 
629
}
 
630
 
 
631
void KexiView::slotSwitchToTextViewModeInternal(bool)
 
632
{
 
633
    slotSwitchToViewModeInternal(Kexi::TextViewMode);
 
634
}
 
635
 
 
636
void KexiView::slotSwitchToViewModeInternal(Kexi::ViewMode mode)
 
637
{
 
638
    if (!d->slotSwitchToViewModeInternalEnabled)
 
639
        return;
 
640
    if (d->recentResultOfSwitchToViewModeInternal != true)
 
641
        d->recentResultOfSwitchToViewModeInternal = true;
 
642
    else
 
643
        d->recentResultOfSwitchToViewModeInternal = d->window->switchToViewModeInternal(mode);
 
644
 
 
645
    if (d->viewMode != mode) {
 
646
        //switch back visually
 
647
        KexiSmallToolButton *b = d->toggleViewModeButtons.value(mode);
 
648
        d->slotSwitchToViewModeInternalEnabled = false;
 
649
        b->setChecked(false);
 
650
        d->slotSwitchToViewModeInternalEnabled = true;
 
651
    }
 
652
}
 
653
 
 
654
void KexiView::initViewActions()
 
655
{
 
656
    if (!d->topBarLyr)
 
657
        return;
 
658
    if (!d->viewActions.isEmpty())
 
659
        d->topBarLyr->addWidget(new KexiToolBarSeparator(d->topBarHWidget));
 
660
    foreach(QAction* action, d->viewActions) {
 
661
        if (action->isSeparator()) {
 
662
            d->topBarLyr->addWidget(new KexiToolBarSeparator(d->topBarHWidget));
 
663
        } else {
 
664
            KexiSmallToolButton *btn = new KexiSmallToolButton(action, d->topBarHWidget);
 
665
            btn->setText(action->text());
 
666
            btn->setToolTip(action->toolTip());
 
667
            btn->setWhatsThis(action->whatsThis());
 
668
            if (action->dynamicPropertyNames().contains("iconOnly") && action->property("iconOnly").toBool() ) {
 
669
                btn->setToolButtonStyle(Qt::ToolButtonIconOnly);
 
670
            }
 
671
            d->topBarLyr->addWidget(btn);
 
672
        }
 
673
    }
 
674
}
 
675
 
 
676
void KexiView::setSortedProperties(bool set)
 
677
{
 
678
    d->sortedProperties = set;
 
679
}
 
680
 
 
681
#include "KexiView.moc"