Commit ecd51c52 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Huge commit to change Gwenview coding style to something closer to other parts of KDE

- tabs => 4 spaces
- Linux bracket style
- No more than one empty line
parent 2995e2c5
kate: tab-indents on; tab-width 4; indent-width 4; replace-tabs off;
kate: tab-indents off; indent-width 4; replace-tabs on;
......@@ -22,39 +22,40 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Local
#include "contextmanager.h"
namespace Gwenview {
namespace Gwenview
{
struct AbstractContextManagerItemPrivate {
ContextManager* mContextManager;
QWidget* mWidget;
ContextManager* mContextManager;
QWidget* mWidget;
};
AbstractContextManagerItem::AbstractContextManagerItem(ContextManager* manager)
: QObject(manager)
, d(new AbstractContextManagerItemPrivate) {
d->mContextManager = manager;
d->mWidget = 0;
, d(new AbstractContextManagerItemPrivate)
{
d->mContextManager = manager;
d->mWidget = 0;
}
AbstractContextManagerItem::~AbstractContextManagerItem() {
delete d;
AbstractContextManagerItem::~AbstractContextManagerItem()
{
delete d;
}
ContextManager* AbstractContextManagerItem::contextManager() const {
return d->mContextManager;
ContextManager* AbstractContextManagerItem::contextManager() const
{
return d->mContextManager;
}
QWidget* AbstractContextManagerItem::widget() const {
return d->mWidget;
QWidget* AbstractContextManagerItem::widget() const
{
return d->mWidget;
}
void AbstractContextManagerItem::setWidget(QWidget* widget) {
d->mWidget = widget;
void AbstractContextManagerItem::setWidget(QWidget* widget)
{
d->mWidget = widget;
}
} // namespace
......@@ -24,27 +24,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Qt
#include <QWidget>
namespace Gwenview {
namespace Gwenview
{
class ContextManager;
struct AbstractContextManagerItemPrivate;
class AbstractContextManagerItem : public QObject {
Q_OBJECT
class AbstractContextManagerItem : public QObject
{
Q_OBJECT
public:
AbstractContextManagerItem(ContextManager*);
virtual ~AbstractContextManagerItem();
AbstractContextManagerItem(ContextManager*);
virtual ~AbstractContextManagerItem();
QWidget* widget() const;
QWidget* widget() const;
ContextManager* contextManager() const;
ContextManager* contextManager() const;
protected:
void setWidget(QWidget* widget);
void setWidget(QWidget* widget);
private:
AbstractContextManagerItemPrivate * const d;
AbstractContextManagerItemPrivate * const d;
};
} // namespace
......
......@@ -33,91 +33,92 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <lib/gwenviewconfig.h>
#include <lib/invisiblebuttongroup.h>
namespace Gwenview {
namespace Gwenview
{
struct ConfigDialogPrivate {
InvisibleButtonGroup* mAlphaBackgroundModeGroup;
InvisibleButtonGroup* mWheelBehaviorGroup;
InvisibleButtonGroup* mThumbnailBarOrientationGroup;
Ui_GeneralConfigPage mGeneralConfigPage;
Ui_ImageViewConfigPage mImageViewConfigPage;
Ui_AdvancedConfigPage mAdvancedConfigPage;
InvisibleButtonGroup* mAlphaBackgroundModeGroup;
InvisibleButtonGroup* mWheelBehaviorGroup;
InvisibleButtonGroup* mThumbnailBarOrientationGroup;
Ui_GeneralConfigPage mGeneralConfigPage;
Ui_ImageViewConfigPage mImageViewConfigPage;
Ui_AdvancedConfigPage mAdvancedConfigPage;
};
template <class Ui>
QWidget* setupPage(Ui& ui) {
QWidget* widget = new QWidget;
ui.setupUi(widget);
widget->layout()->setMargin(0);
return widget;
QWidget* setupPage(Ui& ui)
{
QWidget* widget = new QWidget;
ui.setupUi(widget);
widget->layout()->setMargin(0);
return widget;
}
ConfigDialog::ConfigDialog(QWidget* parent)
: KConfigDialog(parent, "Settings", GwenviewConfig::self())
, d(new ConfigDialogPrivate) {
setFaceType(KPageDialog::List);
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply | KDialog::Default);
showButtonSeparator(true);
QWidget* widget;
KPageWidgetItem* pageItem;
// General
widget = setupPage(d->mGeneralConfigPage);
pageItem = addPage(widget, i18n("General"));
pageItem->setIcon(KIcon("gwenview"));
connect(d->mGeneralConfigPage.kcfg_ViewBackgroundValue, SIGNAL(valueChanged(int)), SLOT(updateViewBackgroundFrame()));
// Image View
widget = setupPage(d->mImageViewConfigPage);
d->mAlphaBackgroundModeGroup = new InvisibleButtonGroup(widget);
d->mAlphaBackgroundModeGroup->setObjectName( QLatin1String("kcfg_AlphaBackgroundMode" ));
d->mAlphaBackgroundModeGroup->addButton(d->mImageViewConfigPage.checkBoardRadioButton, int(RasterImageView::AlphaBackgroundCheckBoard));
d->mAlphaBackgroundModeGroup->addButton(d->mImageViewConfigPage.solidColorRadioButton, int(RasterImageView::AlphaBackgroundSolid));
d->mWheelBehaviorGroup = new InvisibleButtonGroup(widget);
d->mWheelBehaviorGroup->setObjectName( QLatin1String("kcfg_MouseWheelBehavior" ));
d->mWheelBehaviorGroup->addButton(d->mImageViewConfigPage.mouseWheelScrollRadioButton, int(MouseWheelBehavior::Scroll));
d->mWheelBehaviorGroup->addButton(d->mImageViewConfigPage.mouseWheelBrowseRadioButton, int(MouseWheelBehavior::Browse));
d->mThumbnailBarOrientationGroup = new InvisibleButtonGroup(widget);
d->mThumbnailBarOrientationGroup->setObjectName( QLatin1String("kcfg_ThumbnailBarOrientation" ));
d->mThumbnailBarOrientationGroup->addButton(d->mImageViewConfigPage.horizontalRadioButton, int(Qt::Horizontal));
d->mThumbnailBarOrientationGroup->addButton(d->mImageViewConfigPage.verticalRadioButton, int(Qt::Vertical));
pageItem = addPage(widget, i18n("Image View"));
pageItem->setIcon(KIcon("view-preview"));
// Advanced
widget = setupPage(d->mAdvancedConfigPage);
pageItem = addPage(widget, i18n("Advanced"));
pageItem->setIcon(KIcon("preferences-other"));
d->mAdvancedConfigPage.cacheHelpLabel->setFont(KGlobalSettings::smallestReadableFont());
updateViewBackgroundFrame();
, d(new ConfigDialogPrivate)
{
setFaceType(KPageDialog::List);
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply | KDialog::Default);
showButtonSeparator(true);
QWidget* widget;
KPageWidgetItem* pageItem;
// General
widget = setupPage(d->mGeneralConfigPage);
pageItem = addPage(widget, i18n("General"));
pageItem->setIcon(KIcon("gwenview"));
connect(d->mGeneralConfigPage.kcfg_ViewBackgroundValue, SIGNAL(valueChanged(int)), SLOT(updateViewBackgroundFrame()));
// Image View
widget = setupPage(d->mImageViewConfigPage);
d->mAlphaBackgroundModeGroup = new InvisibleButtonGroup(widget);
d->mAlphaBackgroundModeGroup->setObjectName(QLatin1String("kcfg_AlphaBackgroundMode"));
d->mAlphaBackgroundModeGroup->addButton(d->mImageViewConfigPage.checkBoardRadioButton, int(RasterImageView::AlphaBackgroundCheckBoard));
d->mAlphaBackgroundModeGroup->addButton(d->mImageViewConfigPage.solidColorRadioButton, int(RasterImageView::AlphaBackgroundSolid));
d->mWheelBehaviorGroup = new InvisibleButtonGroup(widget);
d->mWheelBehaviorGroup->setObjectName(QLatin1String("kcfg_MouseWheelBehavior"));
d->mWheelBehaviorGroup->addButton(d->mImageViewConfigPage.mouseWheelScrollRadioButton, int(MouseWheelBehavior::Scroll));
d->mWheelBehaviorGroup->addButton(d->mImageViewConfigPage.mouseWheelBrowseRadioButton, int(MouseWheelBehavior::Browse));
d->mThumbnailBarOrientationGroup = new InvisibleButtonGroup(widget);
d->mThumbnailBarOrientationGroup->setObjectName(QLatin1String("kcfg_ThumbnailBarOrientation"));
d->mThumbnailBarOrientationGroup->addButton(d->mImageViewConfigPage.horizontalRadioButton, int(Qt::Horizontal));
d->mThumbnailBarOrientationGroup->addButton(d->mImageViewConfigPage.verticalRadioButton, int(Qt::Vertical));
pageItem = addPage(widget, i18n("Image View"));
pageItem->setIcon(KIcon("view-preview"));
// Advanced
widget = setupPage(d->mAdvancedConfigPage);
pageItem = addPage(widget, i18n("Advanced"));
pageItem->setIcon(KIcon("preferences-other"));
d->mAdvancedConfigPage.cacheHelpLabel->setFont(KGlobalSettings::smallestReadableFont());
updateViewBackgroundFrame();
}
ConfigDialog::~ConfigDialog() {
delete d;
ConfigDialog::~ConfigDialog()
{
delete d;
}
void ConfigDialog::updateViewBackgroundFrame() {
QColor color = QColor::fromHsv(0, 0, d->mGeneralConfigPage.kcfg_ViewBackgroundValue->value());
QString css =
QString(
"background-color: %1;"
"border-radius: 5px;"
"border: 1px solid %1;")
.arg(color.name());
// When using Oxygen, setting the background color via palette causes the
// pixels outside the frame to be painted with the new background color as
// well. Using CSS works more like expected.
d->mGeneralConfigPage.backgroundValueFrame->setStyleSheet(css);
void ConfigDialog::updateViewBackgroundFrame()
{
QColor color = QColor::fromHsv(0, 0, d->mGeneralConfigPage.kcfg_ViewBackgroundValue->value());
QString css =
QString(
"background-color: %1;"
"border-radius: 5px;"
"border: 1px solid %1;")
.arg(color.name());
// When using Oxygen, setting the background color via palette causes the
// pixels outside the frame to be painted with the new background color as
// well. Using CSS works more like expected.
d->mGeneralConfigPage.backgroundValueFrame->setStyleSheet(css);
}
} // namespace
......@@ -28,24 +28,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Local
namespace Gwenview {
namespace Gwenview
{
struct ConfigDialogPrivate;
class ConfigDialog : public KConfigDialog {
Q_OBJECT
class ConfigDialog : public KConfigDialog
{
Q_OBJECT
public:
ConfigDialog(QWidget* parent);
~ConfigDialog();
ConfigDialog(QWidget* parent);
~ConfigDialog();
private Q_SLOTS:
void updateViewBackgroundFrame();
void updateViewBackgroundFrame();
private:
ConfigDialogPrivate* const d;
ConfigDialogPrivate* const d;
};
} // namespace
#endif /* CONFIGDIALOG_H */
......@@ -34,198 +34,199 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <lib/document/documentfactory.h>
#include <lib/semanticinfo/sorteddirmodel.h>
namespace Gwenview {
namespace Gwenview
{
struct ContextManagerPrivate {
QList<AbstractContextManagerItem*> mList;
SortedDirModel* mDirModel;
QItemSelectionModel* mSelectionModel;
KUrl mCurrentDirUrl;
KUrl mCurrentUrl;
bool mOnlyCurrentUrl;
bool mSelectedFileItemListNeedsUpdate;
QSet<QByteArray> mQueuedSignals;
KFileItemList mSelectedFileItemList;
QTimer* mQueuedSignalsTimer;
void queueSignal(const QByteArray& signal) {
mQueuedSignals << signal;
mQueuedSignalsTimer->start();
}
void updateSelectedFileItemList() {
if (!mSelectedFileItemListNeedsUpdate) {
return;
}
mSelectedFileItemList.clear();
if (!mOnlyCurrentUrl) {
QItemSelection selection = mSelectionModel->selection();
Q_FOREACH(const QModelIndex& index, selection.indexes()) {
mSelectedFileItemList << mDirModel->itemForIndex(index);
}
}
// At least add current url if it's valid (it may not be in
// the list if we are viewing a non-browsable url, for example
// using http protocol)
if (mSelectedFileItemList.isEmpty() && mCurrentUrl.isValid()) {
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, mCurrentUrl);
mSelectedFileItemList << item;
}
mSelectedFileItemListNeedsUpdate = false;
}
QList<AbstractContextManagerItem*> mList;
SortedDirModel* mDirModel;
QItemSelectionModel* mSelectionModel;
KUrl mCurrentDirUrl;
KUrl mCurrentUrl;
bool mOnlyCurrentUrl;
bool mSelectedFileItemListNeedsUpdate;
QSet<QByteArray> mQueuedSignals;
KFileItemList mSelectedFileItemList;
QTimer* mQueuedSignalsTimer;
void queueSignal(const QByteArray& signal)
{
mQueuedSignals << signal;
mQueuedSignalsTimer->start();
}
void updateSelectedFileItemList()
{
if (!mSelectedFileItemListNeedsUpdate) {
return;
}
mSelectedFileItemList.clear();
if (!mOnlyCurrentUrl) {
QItemSelection selection = mSelectionModel->selection();
Q_FOREACH(const QModelIndex & index, selection.indexes()) {
mSelectedFileItemList << mDirModel->itemForIndex(index);
}
}
// At least add current url if it's valid (it may not be in
// the list if we are viewing a non-browsable url, for example
// using http protocol)
if (mSelectedFileItemList.isEmpty() && mCurrentUrl.isValid()) {
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, mCurrentUrl);
mSelectedFileItemList << item;
}
mSelectedFileItemListNeedsUpdate = false;
}
};
ContextManager::ContextManager(SortedDirModel* dirModel, QItemSelectionModel* selectionModel, QObject* parent)
: QObject(parent)
, d(new ContextManagerPrivate)
{
d->mQueuedSignalsTimer = new QTimer(this);
d->mQueuedSignalsTimer->setInterval(100);
d->mQueuedSignalsTimer->setSingleShot(true);
connect(d->mQueuedSignalsTimer, SIGNAL(timeout()),
SLOT(emitQueuedSignals()) );
d->mDirModel = dirModel;
connect(d->mDirModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
SLOT(slotDirModelDataChanged(QModelIndex,QModelIndex)) );
d->mSelectionModel = selectionModel;
connect(d->mSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(slotSelectionChanged()) );
connect(d->mSelectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
SLOT(slotCurrentChanged(QModelIndex)) );
d->mSelectedFileItemListNeedsUpdate = false;
d->mOnlyCurrentUrl = false;
d->mQueuedSignalsTimer = new QTimer(this);
d->mQueuedSignalsTimer->setInterval(100);
d->mQueuedSignalsTimer->setSingleShot(true);
connect(d->mQueuedSignalsTimer, SIGNAL(timeout()),
SLOT(emitQueuedSignals()));
d->mDirModel = dirModel;
connect(d->mDirModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
SLOT(slotDirModelDataChanged(QModelIndex, QModelIndex)));
d->mSelectionModel = selectionModel;
connect(d->mSelectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
SLOT(slotSelectionChanged()));
connect(d->mSelectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(slotCurrentChanged(QModelIndex)));
d->mSelectedFileItemListNeedsUpdate = false;
d->mOnlyCurrentUrl = false;
}
ContextManager::~ContextManager() {
qDeleteAll(d->mList);
delete d;
ContextManager::~ContextManager()
{
qDeleteAll(d->mList);
delete d;
}
void ContextManager::addItem(AbstractContextManagerItem* item) {
d->mList << item;
void ContextManager::addItem(AbstractContextManagerItem* item)
{
d->mList << item;
}
void ContextManager::setCurrentUrl(const KUrl& currentUrl)
{
if (d->mCurrentUrl == currentUrl) {
return;
}
void ContextManager::setCurrentUrl(const KUrl& currentUrl) {
if (d->mCurrentUrl == currentUrl) {
return;
}
d->mCurrentUrl = currentUrl;
Document::Ptr doc = DocumentFactory::instance()->load(currentUrl);
QUndoGroup* undoGroup = DocumentFactory::instance()->undoGroup();
undoGroup->addStack(doc->undoStack());
undoGroup->setActiveStack(doc->undoStack());
d->mCurrentUrl = currentUrl;
Document::Ptr doc = DocumentFactory::instance()->load(currentUrl);
QUndoGroup* undoGroup = DocumentFactory::instance()->undoGroup();
undoGroup->addStack(doc->undoStack());
undoGroup->setActiveStack(doc->undoStack());
if (d->mOnlyCurrentUrl) {
d->mSelectedFileItemListNeedsUpdate = true;
}
if (d->mOnlyCurrentUrl) {
d->mSelectedFileItemListNeedsUpdate = true;
}
d->queueSignal("selectionChanged");
d->queueSignal("selectionChanged");
}
KFileItemList ContextManager::selectedFileItemList() const {
d->updateSelectedFileItemList();
return d->mSelectedFileItemList;
KFileItemList ContextManager::selectedFileItemList() const
{
d->updateSelectedFileItemList();
return d->mSelectedFileItemList;
}
void ContextManager::setCurrentDirUrl(const KUrl& url) {
if (url.equals(d->mCurrentDirUrl, KUrl::CompareWithoutTrailingSlash)) {
return;
}
d->mCurrentDirUrl = url;
currentDirUrlChanged();
void ContextManager::setCurrentDirUrl(const KUrl& url)
{
if (url.equals(d->mCurrentDirUrl, KUrl::CompareWithoutTrailingSlash)) {
return;
}
d->mCurrentDirUrl = url;
currentDirUrlChanged();
}
KUrl ContextManager::currentDirUrl() const {
return d->mCurrentDirUrl;
KUrl ContextManager::currentDirUrl() const
{
return d->mCurrentDirUrl;
}
KUrl ContextManager::currentUrl() const {
return d->mCurrentUrl;
KUrl ContextManager::currentUrl() const
{
return d->mCurrentUrl;
}
SortedDirModel* ContextManager::dirModel() const {
return d->mDirModel;
SortedDirModel* ContextManager::dirModel() const
{
return d->mDirModel;
}
void ContextManager::slotDirModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
// Data change can happen in the following cases:
// - items have been renamed
// - item bytes have been modified
// - item meta info has been retrieved or modified
//
// If a selected item is affected, schedule emission of a
// selectionDataChanged() signal. Don't emit it directly to avoid spamming
// the context items in case of a mass change.
QModelIndexList selectionList = d->mSelectionModel->selectedIndexes();
if (selectionList.isEmpty()) {
return;
}
QModelIndexList changedList;
for (int row=topLeft.row(); row <= bottomRight.row(); ++row) {
changedList << d->mDirModel->index(row, 0);
}
QModelIndexList& shortList = selectionList;
QModelIndexList& longList = changedList;
if (shortList.length() > longList.length()) {
qSwap(shortList, longList);
}
Q_FOREACH(const QModelIndex& index, shortList) {
if (longList.contains(index)) {
d->mSelectedFileItemListNeedsUpdate = true;
d->queueSignal("selectionDataChanged");
return;
}
}
void ContextManager::slotDirModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
// Data change can happen in the following cases:
// - items have been renamed
// - item bytes have been modified
// - item meta info has been retrieved or modified
//
// If a selected item is affected, schedule emission of a
// selectionDataChanged() signal. Don't emit it directly to avoid spamming
// the context items in case of a mass change.
QModelIndexList selectionList = d->mSelectionModel->selectedIndexes();
if (selectionList.isEmpty()) {
return;
}
QModelIndexList changedList;
for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
changedList << d->mDirModel->index(row, 0);
}
QModelIndexList& shortList = selectionList;