Changeset View
Changeset View
Standalone View
Standalone View
app/savebar.cpp
| Show All 29 Lines | |||||
| 30 | #include <QIcon> | 30 | #include <QIcon> | ||
| 31 | #include <QUrl> | 31 | #include <QUrl> | ||
| 32 | 32 | | |||
| 33 | // KDE | 33 | // KDE | ||
| 34 | #include <KActionCollection> | 34 | #include <KActionCollection> | ||
| 35 | #include <KColorScheme> | 35 | #include <KColorScheme> | ||
| 36 | #include <KIconLoader> | 36 | #include <KIconLoader> | ||
| 37 | #include <KLocalizedString> | 37 | #include <KLocalizedString> | ||
| 38 | #include <KSqueezedTextLabel> | ||||
| 38 | 39 | | |||
| 39 | // Local | 40 | // Local | ||
| 40 | #include "lib/document/documentfactory.h" | 41 | #include "lib/document/documentfactory.h" | ||
| 41 | #include "lib/gwenviewconfig.h" | 42 | #include "lib/gwenviewconfig.h" | ||
| 42 | #include "lib/memoryutils.h" | 43 | #include "lib/memoryutils.h" | ||
| 43 | #include "lib/paintutils.h" | 44 | #include "lib/paintutils.h" | ||
| 45 | #include "lib/squeezedlinklabel.h" | ||||
| 44 | 46 | | |||
| 45 | namespace Gwenview | 47 | namespace Gwenview | ||
| 46 | { | 48 | { | ||
| 47 | 49 | | |||
| 48 | QToolButton* createToolButton() | 50 | QToolButton* createToolButton() | ||
| 49 | { | 51 | { | ||
| 50 | QToolButton* button = new QToolButton; | 52 | QToolButton* button = new QToolButton; | ||
| 51 | button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 53 | button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||
| 52 | button->hide(); | 54 | button->hide(); | ||
| 53 | return button; | 55 | return button; | ||
| 54 | } | 56 | } | ||
| 55 | 57 | | |||
| 56 | struct SaveBarPrivate | 58 | struct SaveBarPrivate | ||
| 57 | { | 59 | { | ||
| 58 | SaveBar* q; | 60 | SaveBar* q; | ||
| 59 | KActionCollection* mActionCollection; | 61 | KActionCollection* mActionCollection; | ||
| 60 | QWidget* mSaveBarWidget; | 62 | QWidget* mSaveBarWidget; | ||
| 61 | QWidget* mTopRowWidget; | 63 | QWidget* mTopRowWidget; | ||
| 62 | QToolButton* mUndoButton; | 64 | QToolButton* mUndoButton; | ||
| 63 | QToolButton* mRedoButton; | 65 | QToolButton* mRedoButton; | ||
| 64 | QToolButton* mSaveCurrentUrlButton; | 66 | QToolButton* mSaveCurrentUrlButton; | ||
| 65 | QToolButton* mSaveAsButton; | 67 | QToolButton* mSaveAsButton; | ||
| 66 | QToolButton* mSaveAllButton; | 68 | QToolButton* mSaveAllButton; | ||
| 67 | QToolButton* mSaveAllFullScreenButton; | 69 | QToolButton* mSaveAllFullScreenButton; | ||
| 68 | QLabel* mMessageLabel; | 70 | KSqueezedTextLabel* mMessageLabel; | ||
| 69 | QLabel* mActionsLabel; | 71 | SqueezedLinkLabel* mPreviousActionsLabel; | ||
| 72 | QLabel* mActionsLabelSeparator; | ||||
| 73 | SqueezedLinkLabel* mNextActionsLabel; | ||||
| 70 | QFrame* mTooManyChangesFrame; | 74 | QFrame* mTooManyChangesFrame; | ||
| 71 | QUrl mCurrentUrl; | 75 | QUrl mCurrentUrl; | ||
| 72 | 76 | | |||
| 73 | void createTooManyChangesFrame() | 77 | void createTooManyChangesFrame() | ||
| 74 | { | 78 | { | ||
| 75 | mTooManyChangesFrame = new QFrame; | 79 | mTooManyChangesFrame = new QFrame; | ||
| 76 | 80 | | |||
| 77 | // Icon | 81 | // Icon | ||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 165 | Q_FOREACH(const QUrl &url, list) { | |||
| 163 | memoryUsage += doc->memoryUsage(); | 167 | memoryUsage += doc->memoryUsage(); | ||
| 164 | } | 168 | } | ||
| 165 | 169 | | |||
| 166 | mTooManyChangesFrame->setVisible(memoryUsage > maxMemoryUsage); | 170 | mTooManyChangesFrame->setVisible(memoryUsage > maxMemoryUsage); | ||
| 167 | } | 171 | } | ||
| 168 | 172 | | |||
| 169 | void updateTopRowWidget(const QList<QUrl>& lst) | 173 | void updateTopRowWidget(const QList<QUrl>& lst) | ||
| 170 | { | 174 | { | ||
| 171 | QStringList links; | | |||
| 172 | QString message; | 175 | QString message; | ||
| 173 | 176 | | |||
| 174 | if (lst.contains(mCurrentUrl)) { | 177 | if (lst.contains(mCurrentUrl)) { | ||
| 175 | message = i18n("Current image modified"); | 178 | message = i18n("Current image modified"); | ||
| 176 | 179 | | |||
| 177 | mUndoButton->show(); | 180 | mUndoButton->show(); | ||
| 178 | mRedoButton->show(); | 181 | mRedoButton->show(); | ||
| 179 | 182 | | |||
| 180 | if (lst.size() > 1) { | 183 | if (lst.size() > 1) { | ||
| 181 | QString previous = i18n("Previous modified image"); | 184 | mPreviousActionsLabel->setText(i18n("Previous modified image"), | ||
| 182 | QString next = i18n("Next modified image"); | 185 | QStringLiteral("previous"), | ||
| 183 | if (mCurrentUrl == lst[0]) { | 186 | mCurrentUrl == lst.first() ? SqueezedLinkLabel::PlainText | ||
| 184 | links << previous; | 187 | : SqueezedLinkLabel::Link); | ||
| 188 | mPreviousActionsLabel->show(); | ||||
| 189 | mActionsLabelSeparator->show(); | ||||
| 190 | mNextActionsLabel->setText(i18n("Next modified image"), | ||||
| 191 | QStringLiteral("next"), | ||||
| 192 | mCurrentUrl == lst.last() ? SqueezedLinkLabel::PlainText | ||||
| 193 | : SqueezedLinkLabel::Link); | ||||
| 194 | mNextActionsLabel->show(); | ||||
| 185 | } else { | 195 | } else { | ||
| 186 | links << QStringLiteral("<a href='previous'>%1</a>").arg(previous); | 196 | mPreviousActionsLabel->hide(); | ||
| 187 | } | 197 | mActionsLabelSeparator->hide(); | ||
| 188 | if (mCurrentUrl == lst[lst.size() - 1]) { | 198 | mNextActionsLabel->hide(); | ||
| 189 | links << next; | | |||
| 190 | } else { | | |||
| 191 | links << QStringLiteral("<a href='next'>%1</a>").arg(next); | | |||
| 192 | } | | |||
| 193 | } | 199 | } | ||
| 194 | } else { | 200 | } else { | ||
| 195 | mUndoButton->hide(); | 201 | mUndoButton->hide(); | ||
| 196 | mRedoButton->hide(); | 202 | mRedoButton->hide(); | ||
| 197 | 203 | | |||
| 198 | message = i18np("One image modified", "%1 images modified", lst.size()); | 204 | message = i18np("One image modified", "%1 images modified", lst.size()); | ||
| 205 | | ||||
| 199 | if (lst.size() > 1) { | 206 | if (lst.size() > 1) { | ||
| 200 | links << QStringLiteral("<a href='first'>%1</a>").arg(i18n("Go to first modified image")); | 207 | mPreviousActionsLabel->setText(i18n("Go to first modified image"), QStringLiteral("first")); | ||
| 201 | } else { | 208 | } else { | ||
| 202 | links << QStringLiteral("<a href='first'>%1</a>").arg(i18n("Go to it")); | 209 | mPreviousActionsLabel->setText(i18n("Go to it"), QStringLiteral("first")); | ||
| 203 | } | 210 | } | ||
| 211 | mPreviousActionsLabel->show(); | ||||
| 212 | mActionsLabelSeparator->hide(); | ||||
| 213 | mNextActionsLabel->hide(); | ||||
| 204 | } | 214 | } | ||
| 205 | 215 | | |||
| 206 | mSaveCurrentUrlButton->setVisible(lst.contains(mCurrentUrl)); | 216 | mSaveCurrentUrlButton->setVisible(lst.contains(mCurrentUrl)); | ||
| 207 | mSaveAsButton->setVisible(lst.contains(mCurrentUrl)); | 217 | mSaveAsButton->setVisible(lst.contains(mCurrentUrl)); | ||
| 208 | mSaveAllButton->setVisible(lst.size() >= 1); | 218 | mSaveAllButton->setVisible(lst.size() >= 1); | ||
| 209 | 219 | | |||
| 210 | mMessageLabel->setText(message); | 220 | mMessageLabel->setText(message); | ||
| 211 | mMessageLabel->setMaximumWidth(mMessageLabel->minimumSizeHint().width()); | 221 | mMessageLabel->setMaximumWidth(mMessageLabel->sizeHint().width()); | ||
| 212 | mActionsLabel->setText(links.join(" | ")); | 222 | | ||
| 223 | mPreviousActionsLabel->setMaximumWidth(mPreviousActionsLabel->sizeHint().width()); | ||||
| 224 | mNextActionsLabel->setMaximumWidth(mNextActionsLabel->sizeHint().width()); | ||||
| 213 | } | 225 | } | ||
| 214 | 226 | | |||
| 215 | void updateWidgetSizes() | 227 | void updateWidgetSizes() | ||
| 216 | { | 228 | { | ||
| 217 | QVBoxLayout* layout = static_cast<QVBoxLayout*>(mSaveBarWidget->layout()); | 229 | QVBoxLayout* layout = static_cast<QVBoxLayout*>(mSaveBarWidget->layout()); | ||
| 218 | int topRowHeight = q->window()->isFullScreen() ? 0 : mTopRowWidget->height(); | 230 | int topRowHeight = q->window()->isFullScreen() ? 0 : mTopRowWidget->height(); | ||
| 219 | int bottomRowHeight = mTooManyChangesFrame->isVisibleTo(mSaveBarWidget) ? mTooManyChangesFrame->sizeHint().height() : 0; | 231 | int bottomRowHeight = mTooManyChangesFrame->isVisibleTo(mSaveBarWidget) ? mTooManyChangesFrame->sizeHint().height() : 0; | ||
| 220 | 232 | | |||
| Show All 10 Lines | |||||
| 231 | , d(new SaveBarPrivate) | 243 | , d(new SaveBarPrivate) | ||
| 232 | { | 244 | { | ||
| 233 | d->q = this; | 245 | d->q = this; | ||
| 234 | d->mActionCollection = actionCollection; | 246 | d->mActionCollection = actionCollection; | ||
| 235 | d->mSaveBarWidget = new QWidget(); | 247 | d->mSaveBarWidget = new QWidget(); | ||
| 236 | d->mSaveBarWidget->setObjectName(QLatin1String("saveBarWidget")); | 248 | d->mSaveBarWidget->setObjectName(QLatin1String("saveBarWidget")); | ||
| 237 | d->applyNormalStyleSheet(); | 249 | d->applyNormalStyleSheet(); | ||
| 238 | 250 | | |||
| 239 | d->mMessageLabel = new QLabel; | 251 | d->mMessageLabel = new KSqueezedTextLabel; | ||
| 240 | d->mMessageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); | 252 | d->mMessageLabel->setTextElideMode(Qt::ElideRight); | ||
| 241 | 253 | | |||
| 242 | d->mUndoButton = createToolButton(); | 254 | d->mUndoButton = createToolButton(); | ||
| 243 | d->mRedoButton = createToolButton(); | 255 | d->mRedoButton = createToolButton(); | ||
| 244 | d->mSaveCurrentUrlButton = createToolButton(); | 256 | d->mSaveCurrentUrlButton = createToolButton(); | ||
| 245 | d->mSaveAsButton = createToolButton(); | 257 | d->mSaveAsButton = createToolButton(); | ||
| 246 | d->mSaveAllButton = createToolButton(); | 258 | d->mSaveAllButton = createToolButton(); | ||
| 247 | 259 | | |||
| 248 | d->mActionsLabel = new QLabel; | 260 | d->mPreviousActionsLabel = new SqueezedLinkLabel; | ||
| 249 | d->mActionsLabel->setAlignment(Qt::AlignCenter); | 261 | d->mPreviousActionsLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | ||
| 250 | d->mActionsLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); | 262 | d->mActionsLabelSeparator = new QLabel(QStringLiteral("|")); | ||
| 263 | d->mNextActionsLabel = new SqueezedLinkLabel; | ||||
| 251 | 264 | | |||
| 252 | d->createTooManyChangesFrame(); | 265 | d->createTooManyChangesFrame(); | ||
| 253 | 266 | | |||
| 254 | // Setup top row | 267 | // Setup top row | ||
| 255 | d->mTopRowWidget = new QWidget; | 268 | d->mTopRowWidget = new QWidget; | ||
| 256 | QHBoxLayout* rowLayout = new QHBoxLayout(d->mTopRowWidget); | 269 | QHBoxLayout* rowLayout = new QHBoxLayout(d->mTopRowWidget); | ||
| 257 | rowLayout->addWidget(d->mMessageLabel); | 270 | rowLayout->addWidget(d->mMessageLabel, 2); | ||
| 258 | rowLayout->setStretchFactor(d->mMessageLabel, 1); | | |||
| 259 | rowLayout->addWidget(d->mUndoButton); | 271 | rowLayout->addWidget(d->mUndoButton); | ||
| 260 | rowLayout->addWidget(d->mRedoButton); | 272 | rowLayout->addWidget(d->mRedoButton); | ||
| 261 | rowLayout->addWidget(d->mActionsLabel); | 273 | | ||
| 274 | // Use flexible spacers instead of auto-expanding labels | ||||
| 275 | // to center the whole group instead of the separator | ||||
| 276 | rowLayout->addStretch(); | ||||
| 277 | rowLayout->addWidget(d->mPreviousActionsLabel, 1); | ||||
| 278 | rowLayout->addWidget(d->mActionsLabelSeparator); | ||||
| 279 | rowLayout->addWidget(d->mNextActionsLabel, 1); | ||||
| 280 | rowLayout->addStretch(); | ||||
| 281 | | ||||
| 262 | rowLayout->addWidget(d->mSaveCurrentUrlButton); | 282 | rowLayout->addWidget(d->mSaveCurrentUrlButton); | ||
| 263 | rowLayout->addWidget(d->mSaveAsButton); | 283 | rowLayout->addWidget(d->mSaveAsButton); | ||
| 264 | rowLayout->addWidget(d->mSaveAllButton); | 284 | rowLayout->addWidget(d->mSaveAllButton); | ||
| 265 | rowLayout->setMargin(0); | 285 | rowLayout->setMargin(0); | ||
| 266 | 286 | | |||
| 267 | // Setup bottom row | 287 | // Setup bottom row | ||
| 268 | QHBoxLayout* bottomRowLayout = new QHBoxLayout; | 288 | QHBoxLayout* bottomRowLayout = new QHBoxLayout; | ||
| 269 | bottomRowLayout->addStretch(); | 289 | bottomRowLayout->addStretch(); | ||
| 270 | bottomRowLayout->addWidget(d->mTooManyChangesFrame); | 290 | bottomRowLayout->addWidget(d->mTooManyChangesFrame); | ||
| 271 | bottomRowLayout->addStretch(); | 291 | bottomRowLayout->addStretch(); | ||
| 272 | 292 | | |||
| 273 | // Gather everything together | 293 | // Gather everything together | ||
| 274 | QVBoxLayout* layout = new QVBoxLayout(d->mSaveBarWidget); | 294 | QVBoxLayout* layout = new QVBoxLayout(d->mSaveBarWidget); | ||
| 275 | layout->addWidget(d->mTopRowWidget); | 295 | layout->addWidget(d->mTopRowWidget); | ||
| 276 | layout->addLayout(bottomRowLayout); | 296 | layout->addLayout(bottomRowLayout); | ||
| 277 | layout->setMargin(3); | 297 | layout->setMargin(3); | ||
| 278 | layout->setSpacing(3); | 298 | layout->setSpacing(3); | ||
| 279 | 299 | | |||
| 280 | setContent(d->mSaveBarWidget); | 300 | setContent(d->mSaveBarWidget); | ||
| 281 | 301 | | |||
| 282 | connect(DocumentFactory::instance(), SIGNAL(modifiedDocumentListChanged()), | 302 | connect(DocumentFactory::instance(), SIGNAL(modifiedDocumentListChanged()), | ||
| 283 | SLOT(updateContent())); | 303 | SLOT(updateContent())); | ||
| 284 | 304 | | |||
| 285 | connect(d->mActionsLabel, &QLabel::linkActivated, this, &SaveBar::triggerAction); | 305 | connect(d->mPreviousActionsLabel, &QLabel::linkActivated, this, &SaveBar::triggerAction); | ||
| 306 | connect(d->mNextActionsLabel, &QLabel::linkActivated, this, &SaveBar::triggerAction); | ||||
| 286 | } | 307 | } | ||
| 287 | 308 | | |||
| 288 | SaveBar::~SaveBar() | 309 | SaveBar::~SaveBar() | ||
| 289 | { | 310 | { | ||
| 290 | delete d; | 311 | delete d; | ||
| 291 | } | 312 | } | ||
| 292 | 313 | | |||
| 293 | void SaveBar::initActionDependentWidgets() | 314 | void SaveBar::initActionDependentWidgets() | ||
| ▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines | |||||