~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to app/savebar.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
2
2
/*
3
3
Gwenview: an image viewer
4
4
Copyright 2007 AurĆ©lien GĆ¢teau <agateau@kde.org>
42
42
#include "lib/memoryutils.h"
43
43
#include "lib/paintutils.h"
44
44
 
45
 
namespace Gwenview {
46
 
 
47
 
 
48
 
QToolButton* createToolButton() {
49
 
        QToolButton* button = new QToolButton;
50
 
        button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
51
 
        button->hide();
52
 
        return button;
 
45
namespace Gwenview
 
46
{
 
47
 
 
48
QToolButton* createToolButton()
 
49
{
 
50
    QToolButton* button = new QToolButton;
 
51
    button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
 
52
    button->hide();
 
53
    return button;
53
54
}
54
55
 
55
 
 
56
56
struct SaveBarPrivate {
57
 
        SaveBar* that;
58
 
        KActionCollection* mActionCollection;
59
 
        QWidget* mSaveBarWidget;
60
 
        QWidget* mTopRowWidget;
61
 
        QToolButton* mUndoButton;
62
 
        QToolButton* mRedoButton;
63
 
        QToolButton* mSaveCurrentUrlButton;
64
 
        QToolButton* mSaveAsButton;
65
 
        QToolButton* mSaveAllButton;
66
 
        QToolButton* mSaveAllFullScreenButton;
67
 
        QLabel* mMessageLabel;
68
 
        QLabel* mActionsLabel;
69
 
        QFrame* mTooManyChangesFrame;
70
 
        KUrl mCurrentUrl;
71
 
        bool mFullScreenMode;
72
 
 
73
 
        void createTooManyChangesFrame() {
74
 
                mTooManyChangesFrame = new QFrame;
75
 
 
76
 
                // Icon
77
 
                QLabel* iconLabel = new QLabel;
78
 
                QPixmap pix = KIconLoader::global()->loadIcon(
79
 
                        "dialog-warning", KIconLoader::Dialog, KIconLoader::SizeSmall);
80
 
                iconLabel->setPixmap(pix);
81
 
 
82
 
                // Text label
83
 
                QLabel* textLabel = new QLabel;
84
 
                textLabel->setText(
85
 
                        i18n("You have modified many images. To avoid memory problems, you should save your changes.")
86
 
                        );
87
 
 
88
 
                mSaveAllFullScreenButton = createToolButton();
89
 
 
90
 
                // Layout
91
 
                QHBoxLayout* layout = new QHBoxLayout(mTooManyChangesFrame);
92
 
                layout->setMargin(0);
93
 
                layout->addWidget(iconLabel);
94
 
                layout->addWidget(textLabel);
95
 
                layout->addWidget(mSaveAllFullScreenButton);
96
 
                mTooManyChangesFrame->hide();
97
 
 
98
 
                // CSS
99
 
                KColorScheme scheme(mSaveBarWidget->palette().currentColorGroup(), KColorScheme::Window);
100
 
                QColor warningBackgroundColor = scheme.background(KColorScheme::NegativeBackground).color();
101
 
                QColor warningBorderColor = PaintUtils::adjustedHsv(warningBackgroundColor, 0, 150, 0);
102
 
                QColor warningColor = scheme.foreground(KColorScheme::NegativeText).color();
103
 
 
104
 
                QString css =
105
 
                        ".QFrame {"
106
 
                        "       background-color: %1;"
107
 
                        "       border: 1px solid %2;"
108
 
                        "       border-radius: 4px;"
109
 
                        "       padding: 3px;"
110
 
                        "}"
111
 
                        ".QFrame QLabel {"
112
 
                        "       color: %3;"
113
 
                        "}"
114
 
                        ;
115
 
                css = css
116
 
                        .arg(warningBackgroundColor.name())
117
 
                        .arg(warningBorderColor.name())
118
 
                        .arg(warningColor.name())
119
 
                        ;
120
 
                mTooManyChangesFrame->setStyleSheet(css);
121
 
        }
122
 
 
123
 
        void applyNormalStyleSheet() {
124
 
                QColor bgColor = QToolTip::palette().base().color();
125
 
                QColor borderColor = PaintUtils::adjustedHsv(bgColor, 0, 150, 0);
126
 
                QColor fgColor = QToolTip::palette().text().color();
127
 
 
128
 
                QString css =
129
 
                        "#saveBarWidget {"
130
 
                        "       background-color: %1;"
131
 
                        "       border-top: 1px solid %2;"
132
 
                        "       border-bottom: 1px solid %2;"
133
 
                        "       color: %3;"
134
 
                        "}"
135
 
                        ;
136
 
 
137
 
                css = css
138
 
                        .arg(bgColor.name())
139
 
                        .arg(borderColor.name())
140
 
                        .arg(fgColor.name())
141
 
                        ;
142
 
                mSaveBarWidget->setStyleSheet(css);
143
 
        }
144
 
 
145
 
        void applyFullScreenStyleSheet() {
146
 
                QString css =
147
 
                        "#saveBarWidget {"
148
 
                        "       background-color: #333;"
149
 
                        "}";
150
 
                mSaveBarWidget->setStyleSheet(css);
151
 
        }
152
 
 
153
 
 
154
 
        void updateTooManyChangesFrame(const QList<KUrl>& list) {
155
 
                qreal maxPercentageOfMemoryUsage = GwenviewConfig::percentageOfMemoryUsageWarning();
156
 
                qulonglong maxMemoryUsage = MemoryUtils::getTotalMemory() * maxPercentageOfMemoryUsage;
157
 
                qulonglong memoryUsage = 0;
158
 
                Q_FOREACH(const KUrl& url, list) {
159
 
                        Document::Ptr doc = DocumentFactory::instance()->load(url);
160
 
                        memoryUsage += doc->memoryUsage();
161
 
                }
162
 
 
163
 
                mTooManyChangesFrame->setVisible(memoryUsage > maxMemoryUsage);
164
 
        }
165
 
 
166
 
 
167
 
        void updateTopRowWidget(const QList<KUrl>& lst) {
168
 
                QStringList links;
169
 
                QString message;
170
 
 
171
 
                if (lst.contains(mCurrentUrl)) {
172
 
                        message = i18n("Current image modified");
173
 
 
174
 
                        mUndoButton->show();
175
 
                        mRedoButton->show();
176
 
 
177
 
                        if (lst.size() > 1) {
178
 
                                QString previous = i18n("Previous modified image");
179
 
                                QString next = i18n("Next modified image");
180
 
                                if (mCurrentUrl == lst[0]) {
181
 
                                        links << previous;
182
 
                                } else {
183
 
                                        links << QString("<a href='previous'>%1</a>").arg(previous);
184
 
                                }
185
 
                                if (mCurrentUrl == lst[lst.size() - 1]) {
186
 
                                        links << next;
187
 
                                } else {
188
 
                                        links << QString("<a href='next'>%1</a>").arg(next);
189
 
                                }
190
 
                        }
191
 
                } else {
192
 
                        mUndoButton->hide();
193
 
                        mRedoButton->hide();
194
 
 
195
 
                        message = i18np("One image modified", "%1 images modified", lst.size());
196
 
                        if (lst.size() > 1) {
197
 
                                links << QString("<a href='first'>%1</a>").arg(i18n("Go to first modified image"));
198
 
                        } else {
199
 
                                links << QString("<a href='first'>%1</a>").arg(i18n("Go to it"));
200
 
                        }
201
 
                }
202
 
 
203
 
                mSaveCurrentUrlButton->setVisible(lst.contains(mCurrentUrl));
204
 
                mSaveAsButton->setVisible(lst.contains(mCurrentUrl));
205
 
                mSaveAllButton->setVisible(lst.size() >= 1);
206
 
 
207
 
                mMessageLabel->setText(message);
208
 
                mActionsLabel->setText(links.join(" | "));
209
 
        }
210
 
 
211
 
 
212
 
        void updateWidgetSizes() {
213
 
                QVBoxLayout* layout = static_cast<QVBoxLayout*>(mSaveBarWidget->layout());
214
 
                int topRowHeight = mFullScreenMode ? 0 : mTopRowWidget->height();
215
 
                int bottomRowHeight = mTooManyChangesFrame->isVisibleTo(mSaveBarWidget) ? mTooManyChangesFrame->sizeHint().height() : 0;
216
 
 
217
 
                int height = 2 * layout->margin() + topRowHeight + bottomRowHeight;
218
 
                if (topRowHeight > 0 && bottomRowHeight > 0) {
219
 
                        height += layout->spacing();
220
 
                }
221
 
                mSaveBarWidget->setFixedHeight(height);
222
 
                that->setFixedHeight(height);
223
 
        }
 
57
    SaveBar* q;
 
58
    KActionCollection* mActionCollection;
 
59
    QWidget* mSaveBarWidget;
 
60
    QWidget* mTopRowWidget;
 
61
    QToolButton* mUndoButton;
 
62
    QToolButton* mRedoButton;
 
63
    QToolButton* mSaveCurrentUrlButton;
 
64
    QToolButton* mSaveAsButton;
 
65
    QToolButton* mSaveAllButton;
 
66
    QToolButton* mSaveAllFullScreenButton;
 
67
    QLabel* mMessageLabel;
 
68
    QLabel* mActionsLabel;
 
69
    QFrame* mTooManyChangesFrame;
 
70
    KUrl mCurrentUrl;
 
71
    bool mFullScreenMode;
 
72
 
 
73
    void createTooManyChangesFrame()
 
74
    {
 
75
        mTooManyChangesFrame = new QFrame;
 
76
 
 
77
        // Icon
 
78
        QLabel* iconLabel = new QLabel;
 
79
        QPixmap pix = KIconLoader::global()->loadIcon(
 
80
                          "dialog-warning", KIconLoader::Dialog, KIconLoader::SizeSmall);
 
81
        iconLabel->setPixmap(pix);
 
82
 
 
83
        // Text label
 
84
        QLabel* textLabel = new QLabel;
 
85
        textLabel->setText(
 
86
            i18n("You have modified many images. To avoid memory problems, you should save your changes.")
 
87
        );
 
88
 
 
89
        mSaveAllFullScreenButton = createToolButton();
 
90
 
 
91
        // Layout
 
92
        QHBoxLayout* layout = new QHBoxLayout(mTooManyChangesFrame);
 
93
        layout->setMargin(0);
 
94
        layout->addWidget(iconLabel);
 
95
        layout->addWidget(textLabel);
 
96
        layout->addWidget(mSaveAllFullScreenButton);
 
97
        mTooManyChangesFrame->hide();
 
98
 
 
99
        // CSS
 
100
        KColorScheme scheme(mSaveBarWidget->palette().currentColorGroup(), KColorScheme::Window);
 
101
        QColor warningBackgroundColor = scheme.background(KColorScheme::NegativeBackground).color();
 
102
        QColor warningBorderColor = PaintUtils::adjustedHsv(warningBackgroundColor, 0, 150, 0);
 
103
        QColor warningColor = scheme.foreground(KColorScheme::NegativeText).color();
 
104
 
 
105
        QString css =
 
106
            ".QFrame {"
 
107
            "   background-color: %1;"
 
108
            "   border: 1px solid %2;"
 
109
            "   border-radius: 4px;"
 
110
            "   padding: 3px;"
 
111
            "}"
 
112
            ".QFrame QLabel {"
 
113
            "   color: %3;"
 
114
            "}"
 
115
            ;
 
116
        css = css
 
117
              .arg(warningBackgroundColor.name())
 
118
              .arg(warningBorderColor.name())
 
119
              .arg(warningColor.name())
 
120
              ;
 
121
        mTooManyChangesFrame->setStyleSheet(css);
 
122
    }
 
123
 
 
124
    void applyNormalStyleSheet()
 
125
    {
 
126
        QColor bgColor = QToolTip::palette().base().color();
 
127
        QColor borderColor = PaintUtils::adjustedHsv(bgColor, 0, 150, 0);
 
128
        QColor fgColor = QToolTip::palette().text().color();
 
129
 
 
130
        QString css =
 
131
            "#saveBarWidget {"
 
132
            "   background-color: %1;"
 
133
            "   border-top: 1px solid %2;"
 
134
            "   border-bottom: 1px solid %2;"
 
135
            "   color: %3;"
 
136
            "}"
 
137
            ;
 
138
 
 
139
        css = css
 
140
              .arg(bgColor.name())
 
141
              .arg(borderColor.name())
 
142
              .arg(fgColor.name())
 
143
              ;
 
144
        mSaveBarWidget->setStyleSheet(css);
 
145
    }
 
146
 
 
147
    void applyFullScreenStyleSheet()
 
148
    {
 
149
        QString css =
 
150
            "#saveBarWidget {"
 
151
            "   background-color: #333;"
 
152
            "}";
 
153
        mSaveBarWidget->setStyleSheet(css);
 
154
    }
 
155
 
 
156
    void updateTooManyChangesFrame(const QList<KUrl>& list)
 
157
    {
 
158
        qreal maxPercentageOfMemoryUsage = GwenviewConfig::percentageOfMemoryUsageWarning();
 
159
        qulonglong maxMemoryUsage = MemoryUtils::getTotalMemory() * maxPercentageOfMemoryUsage;
 
160
        qulonglong memoryUsage = 0;
 
161
        Q_FOREACH(const KUrl & url, list) {
 
162
            Document::Ptr doc = DocumentFactory::instance()->load(url);
 
163
            memoryUsage += doc->memoryUsage();
 
164
        }
 
165
 
 
166
        mTooManyChangesFrame->setVisible(memoryUsage > maxMemoryUsage);
 
167
    }
 
168
 
 
169
    void updateTopRowWidget(const QList<KUrl>& lst)
 
170
    {
 
171
        QStringList links;
 
172
        QString message;
 
173
 
 
174
        if (lst.contains(mCurrentUrl)) {
 
175
            message = i18n("Current image modified");
 
176
 
 
177
            mUndoButton->show();
 
178
            mRedoButton->show();
 
179
 
 
180
            if (lst.size() > 1) {
 
181
                QString previous = i18n("Previous modified image");
 
182
                QString next = i18n("Next modified image");
 
183
                if (mCurrentUrl == lst[0]) {
 
184
                    links << previous;
 
185
                } else {
 
186
                    links << QString("<a href='previous'>%1</a>").arg(previous);
 
187
                }
 
188
                if (mCurrentUrl == lst[lst.size() - 1]) {
 
189
                    links << next;
 
190
                } else {
 
191
                    links << QString("<a href='next'>%1</a>").arg(next);
 
192
                }
 
193
            }
 
194
        } else {
 
195
            mUndoButton->hide();
 
196
            mRedoButton->hide();
 
197
 
 
198
            message = i18np("One image modified", "%1 images modified", lst.size());
 
199
            if (lst.size() > 1) {
 
200
                links << QString("<a href='first'>%1</a>").arg(i18n("Go to first modified image"));
 
201
            } else {
 
202
                links << QString("<a href='first'>%1</a>").arg(i18n("Go to it"));
 
203
            }
 
204
        }
 
205
 
 
206
        mSaveCurrentUrlButton->setVisible(lst.contains(mCurrentUrl));
 
207
        mSaveAsButton->setVisible(lst.contains(mCurrentUrl));
 
208
        mSaveAllButton->setVisible(lst.size() >= 1);
 
209
 
 
210
        mMessageLabel->setText(message);
 
211
        mActionsLabel->setText(links.join(" | "));
 
212
    }
 
213
 
 
214
    void updateWidgetSizes()
 
215
    {
 
216
        QVBoxLayout* layout = static_cast<QVBoxLayout*>(mSaveBarWidget->layout());
 
217
        int topRowHeight = mFullScreenMode ? 0 : mTopRowWidget->height();
 
218
        int bottomRowHeight = mTooManyChangesFrame->isVisibleTo(mSaveBarWidget) ? mTooManyChangesFrame->sizeHint().height() : 0;
 
219
 
 
220
        int height = 2 * layout->margin() + topRowHeight + bottomRowHeight;
 
221
        if (topRowHeight > 0 && bottomRowHeight > 0) {
 
222
            height += layout->spacing();
 
223
        }
 
224
        mSaveBarWidget->setFixedHeight(height);
 
225
    }
224
226
};
225
227
 
226
 
 
227
228
SaveBar::SaveBar(QWidget* parent, KActionCollection* actionCollection)
228
229
: SlideContainer(parent)
229
 
, d(new SaveBarPrivate) {
230
 
        d->that = this;
231
 
        d->mFullScreenMode = false;
232
 
        d->mActionCollection = actionCollection;
233
 
        d->mSaveBarWidget = new QWidget();
234
 
        d->mSaveBarWidget->setObjectName( QLatin1String("saveBarWidget" ));
235
 
        d->applyNormalStyleSheet();
236
 
 
237
 
        d->mMessageLabel = new QLabel;
238
 
        d->mMessageLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
239
 
 
240
 
        d->mUndoButton = createToolButton();
241
 
        d->mRedoButton = createToolButton();
242
 
        d->mSaveCurrentUrlButton = createToolButton();
243
 
        d->mSaveAsButton = createToolButton();
244
 
        d->mSaveAllButton = createToolButton();
245
 
 
246
 
        d->mActionsLabel = new QLabel;
247
 
        d->mActionsLabel->setAlignment(Qt::AlignCenter);
248
 
        d->mActionsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
249
 
 
250
 
        d->createTooManyChangesFrame();
251
 
 
252
 
        // Setup top row
253
 
        d->mTopRowWidget = new QWidget;
254
 
        QHBoxLayout* rowLayout = new QHBoxLayout(d->mTopRowWidget);
255
 
        rowLayout->addWidget(d->mMessageLabel);
256
 
        rowLayout->addWidget(d->mUndoButton);
257
 
        rowLayout->addWidget(d->mRedoButton);
258
 
        rowLayout->addWidget(d->mActionsLabel);
259
 
        rowLayout->addWidget(d->mSaveCurrentUrlButton);
260
 
        rowLayout->addWidget(d->mSaveAsButton);
261
 
        rowLayout->addWidget(d->mSaveAllButton);
262
 
        rowLayout->setMargin(0);
263
 
 
264
 
        // Setup bottom row
265
 
        QHBoxLayout* bottomRowLayout = new QHBoxLayout;
266
 
        bottomRowLayout->addStretch();
267
 
        bottomRowLayout->addWidget(d->mTooManyChangesFrame);
268
 
        bottomRowLayout->addStretch();
269
 
 
270
 
        // Gather everything together
271
 
        QVBoxLayout* layout = new QVBoxLayout(d->mSaveBarWidget);
272
 
        layout->addWidget(d->mTopRowWidget);
273
 
        layout->addLayout(bottomRowLayout);
274
 
        layout->setMargin(3);
275
 
        layout->setSpacing(3);
276
 
 
277
 
        hide();
278
 
 
279
 
        setContent(d->mSaveBarWidget);
280
 
 
281
 
        connect(DocumentFactory::instance(), SIGNAL(modifiedDocumentListChanged()),
282
 
                SLOT(updateContent()) );
283
 
 
284
 
        connect(d->mActionsLabel, SIGNAL(linkActivated(const QString&)),
285
 
                SLOT(triggerAction(const QString&)) );
286
 
}
287
 
 
288
 
 
289
 
SaveBar::~SaveBar() {
290
 
        delete d;
291
 
}
292
 
 
293
 
 
294
 
void SaveBar::initActionDependentWidgets() {
295
 
        d->mUndoButton->setDefaultAction(d->mActionCollection->action("edit_undo"));
296
 
        d->mRedoButton->setDefaultAction(d->mActionCollection->action("edit_redo"));
297
 
        d->mSaveCurrentUrlButton->setDefaultAction(d->mActionCollection->action("file_save"));
298
 
        d->mSaveAsButton->setDefaultAction(d->mActionCollection->action("file_save_as"));
299
 
 
300
 
        // FIXME: Not using an action for now
301
 
        d->mSaveAllButton->setText(i18n("Save All"));
302
 
        d->mSaveAllButton->setIcon(KIcon("document-save-all"));
303
 
        connect(d->mSaveAllButton, SIGNAL(clicked()),
304
 
                SIGNAL(requestSaveAll()) );
305
 
 
306
 
        d->mSaveAllFullScreenButton->setText(i18n("Save All"));
307
 
        connect(d->mSaveAllFullScreenButton, SIGNAL(clicked()),
308
 
                SIGNAL(requestSaveAll()) );
309
 
 
310
 
        int height = d->mUndoButton->sizeHint().height();
311
 
        d->mTopRowWidget->setFixedHeight(height);
312
 
        d->updateWidgetSizes();
313
 
}
314
 
 
315
 
 
316
 
void SaveBar::setFullScreenMode(bool value) {
317
 
        d->mFullScreenMode = value;
318
 
        d->mSaveAllFullScreenButton->setVisible(value);
319
 
        if (value) {
320
 
                d->applyFullScreenStyleSheet();
321
 
        } else {
322
 
                d->applyNormalStyleSheet();
323
 
        }
324
 
        updateContent();
325
 
}
326
 
 
327
 
 
328
 
void SaveBar::updateContent() {
329
 
        QList<KUrl> lst = DocumentFactory::instance()->modifiedDocumentList();
330
 
        if (lst.size() == 0) {
331
 
                slideOut();
332
 
                return;
333
 
        }
334
 
 
335
 
        if (d->mFullScreenMode) {
336
 
                d->mTopRowWidget->hide();
337
 
        } else {
338
 
                d->mTopRowWidget->show();
339
 
                d->updateTopRowWidget(lst);
340
 
        }
341
 
 
342
 
        d->updateTooManyChangesFrame(lst);
343
 
 
344
 
        d->updateWidgetSizes();
345
 
        if (d->mFullScreenMode && !d->mTooManyChangesFrame->isVisibleTo(d->mSaveBarWidget)) {
346
 
                slideOut();
347
 
        } else {
348
 
                slideIn();
349
 
        }
350
 
}
351
 
 
352
 
 
353
 
void SaveBar::triggerAction(const QString& action) {
354
 
        QList<KUrl> lst = DocumentFactory::instance()->modifiedDocumentList();
355
 
        if (action == "first") {
356
 
                goToUrl(lst[0]);
357
 
        } else if (action == "previous") {
358
 
                int pos = lst.indexOf(d->mCurrentUrl);
359
 
                --pos;
360
 
                Q_ASSERT(pos >= 0);
361
 
                goToUrl(lst[pos]);
362
 
        } else if (action == "next") {
363
 
                int pos = lst.indexOf(d->mCurrentUrl);
364
 
                ++pos;
365
 
                Q_ASSERT(pos < lst.size());
366
 
                goToUrl(lst[pos]);
367
 
        } else {
368
 
                kWarning() << "Unknown action: " << action ;
369
 
        }
370
 
}
371
 
 
372
 
 
373
 
void SaveBar::setCurrentUrl(const KUrl& url) {
374
 
        d->mCurrentUrl = url;
375
 
        updateContent();
376
 
}
377
 
 
 
230
, d(new SaveBarPrivate)
 
231
{
 
232
    d->q = this;
 
233
    d->mFullScreenMode = false;
 
234
    d->mActionCollection = actionCollection;
 
235
    d->mSaveBarWidget = new QWidget();
 
236
    d->mSaveBarWidget->setObjectName(QLatin1String("saveBarWidget"));
 
237
    d->applyNormalStyleSheet();
 
238
 
 
239
    d->mMessageLabel = new QLabel;
 
240
    d->mMessageLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
241
 
 
242
    d->mUndoButton = createToolButton();
 
243
    d->mRedoButton = createToolButton();
 
244
    d->mSaveCurrentUrlButton = createToolButton();
 
245
    d->mSaveAsButton = createToolButton();
 
246
    d->mSaveAllButton = createToolButton();
 
247
 
 
248
    d->mActionsLabel = new QLabel;
 
249
    d->mActionsLabel->setAlignment(Qt::AlignCenter);
 
250
    d->mActionsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
251
 
 
252
    d->createTooManyChangesFrame();
 
253
 
 
254
    // Setup top row
 
255
    d->mTopRowWidget = new QWidget;
 
256
    QHBoxLayout* rowLayout = new QHBoxLayout(d->mTopRowWidget);
 
257
    rowLayout->addWidget(d->mMessageLabel);
 
258
    rowLayout->addWidget(d->mUndoButton);
 
259
    rowLayout->addWidget(d->mRedoButton);
 
260
    rowLayout->addWidget(d->mActionsLabel);
 
261
    rowLayout->addWidget(d->mSaveCurrentUrlButton);
 
262
    rowLayout->addWidget(d->mSaveAsButton);
 
263
    rowLayout->addWidget(d->mSaveAllButton);
 
264
    rowLayout->setMargin(0);
 
265
 
 
266
    // Setup bottom row
 
267
    QHBoxLayout* bottomRowLayout = new QHBoxLayout;
 
268
    bottomRowLayout->addStretch();
 
269
    bottomRowLayout->addWidget(d->mTooManyChangesFrame);
 
270
    bottomRowLayout->addStretch();
 
271
 
 
272
    // Gather everything together
 
273
    QVBoxLayout* layout = new QVBoxLayout(d->mSaveBarWidget);
 
274
    layout->addWidget(d->mTopRowWidget);
 
275
    layout->addLayout(bottomRowLayout);
 
276
    layout->setMargin(3);
 
277
    layout->setSpacing(3);
 
278
 
 
279
    setContent(d->mSaveBarWidget);
 
280
 
 
281
    connect(DocumentFactory::instance(), SIGNAL(modifiedDocumentListChanged()),
 
282
            SLOT(updateContent()));
 
283
 
 
284
    connect(d->mActionsLabel, SIGNAL(linkActivated(QString)),
 
285
            SLOT(triggerAction(QString)));
 
286
}
 
287
 
 
288
SaveBar::~SaveBar()
 
289
{
 
290
    delete d;
 
291
}
 
292
 
 
293
void SaveBar::initActionDependentWidgets()
 
294
{
 
295
    d->mUndoButton->setDefaultAction(d->mActionCollection->action("edit_undo"));
 
296
    d->mRedoButton->setDefaultAction(d->mActionCollection->action("edit_redo"));
 
297
    d->mSaveCurrentUrlButton->setDefaultAction(d->mActionCollection->action("file_save"));
 
298
    d->mSaveAsButton->setDefaultAction(d->mActionCollection->action("file_save_as"));
 
299
 
 
300
    // FIXME: Not using an action for now
 
301
    d->mSaveAllButton->setText(i18n("Save All"));
 
302
    d->mSaveAllButton->setIcon(KIcon("document-save-all"));
 
303
    connect(d->mSaveAllButton, SIGNAL(clicked()),
 
304
            SIGNAL(requestSaveAll()));
 
305
 
 
306
    d->mSaveAllFullScreenButton->setText(i18n("Save All"));
 
307
    connect(d->mSaveAllFullScreenButton, SIGNAL(clicked()),
 
308
            SIGNAL(requestSaveAll()));
 
309
 
 
310
    int height = d->mUndoButton->sizeHint().height();
 
311
    d->mTopRowWidget->setFixedHeight(height);
 
312
    d->updateWidgetSizes();
 
313
}
 
314
 
 
315
void SaveBar::setFullScreenMode(bool value)
 
316
{
 
317
    d->mFullScreenMode = value;
 
318
    d->mSaveAllFullScreenButton->setVisible(value);
 
319
    if (value) {
 
320
        d->applyFullScreenStyleSheet();
 
321
    } else {
 
322
        d->applyNormalStyleSheet();
 
323
    }
 
324
    updateContent();
 
325
}
 
326
 
 
327
void SaveBar::updateContent()
 
328
{
 
329
    QList<KUrl> lst = DocumentFactory::instance()->modifiedDocumentList();
 
330
 
 
331
    if (d->mFullScreenMode) {
 
332
        d->mTopRowWidget->hide();
 
333
    } else {
 
334
        d->mTopRowWidget->show();
 
335
        d->updateTopRowWidget(lst);
 
336
    }
 
337
 
 
338
    d->updateTooManyChangesFrame(lst);
 
339
 
 
340
    d->updateWidgetSizes();
 
341
    if (lst.isEmpty() || (d->mFullScreenMode && !d->mTooManyChangesFrame->isVisibleTo(d->mSaveBarWidget))) {
 
342
        slideOut();
 
343
    } else {
 
344
        slideIn();
 
345
    }
 
346
}
 
347
 
 
348
void SaveBar::triggerAction(const QString& action)
 
349
{
 
350
    QList<KUrl> lst = DocumentFactory::instance()->modifiedDocumentList();
 
351
    if (action == "first") {
 
352
        goToUrl(lst[0]);
 
353
    } else if (action == "previous") {
 
354
        int pos = lst.indexOf(d->mCurrentUrl);
 
355
        --pos;
 
356
        Q_ASSERT(pos >= 0);
 
357
        goToUrl(lst[pos]);
 
358
    } else if (action == "next") {
 
359
        int pos = lst.indexOf(d->mCurrentUrl);
 
360
        ++pos;
 
361
        Q_ASSERT(pos < lst.size());
 
362
        goToUrl(lst[pos]);
 
363
    } else {
 
364
        kWarning() << "Unknown action: " << action ;
 
365
    }
 
366
}
 
367
 
 
368
void SaveBar::setCurrentUrl(const KUrl& url)
 
369
{
 
370
    d->mCurrentUrl = url;
 
371
    updateContent();
 
372
}
378
373
 
379
374
} // namespace