diff --git a/src/lib/marble/CMakeLists.txt b/src/lib/marble/CMakeLists.txt --- a/src/lib/marble/CMakeLists.txt +++ b/src/lib/marble/CMakeLists.txt @@ -175,6 +175,8 @@ MovieCaptureDialog.cpp TourCaptureDialog.cpp EditPlacemarkDialog.cpp + IconChooserDialog.cpp + IconChooserModel.cpp AddLinkDialog.cpp FormattedTextWidget.cpp @@ -281,6 +283,8 @@ cloudsync/BookmarkSyncManager.cpp cloudsync/MergeItem.cpp cloudsync/ConflictDialog.cpp + + ) @@ -340,6 +344,7 @@ MovieCaptureDialog.ui TourCaptureDialog.ui EditPlacemarkDialog.ui + IconChooserDialog.ui AddLinkDialog.ui FormattedTextWidget.ui ElevationWidget.ui @@ -563,6 +568,8 @@ Planet.h PlanetFactory.h EditPlacemarkDialog.h + IconChooserDialog.h + IconChooserModel.h AddLinkDialog.h FormattedTextWidget.h diff --git a/src/lib/marble/IconChooserDialog.h b/src/lib/marble/IconChooserDialog.h new file mode 100644 --- /dev/null +++ b/src/lib/marble/IconChooserDialog.h @@ -0,0 +1,49 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2016 Akshat Tandon +// + +#ifndef MARBLE_ICONCHOOSERDIALOG_H +#define MARBLE_ICONCHOOSERDIALOG_H + +#include "ui_IconChooserDialog.h" +#include "marble_export.h" + +#include +#include + +namespace Marble +{ + + class IconChooserDialogPrivate; + +class MARBLE_EXPORT IconChooserDialog : public QDialog, private Ui::UiIconChooserDialog +{ + Q_OBJECT + + public: + /** Constructor */ + explicit IconChooserDialog( QWidget *parent = 0 ); + + /** Destructor */ + ~IconChooserDialog(); + + const QString& iconPath() const; + +private: + + Q_PRIVATE_SLOT( d, void customIcon() ) + Q_PRIVATE_SLOT( d, void handleIconSelection( const QModelIndex &index ) ) + + Q_DISABLE_COPY( IconChooserDialog ) + IconChooserDialogPrivate* const d; + friend class IconChooserDialogPrivate; +}; + +} +#endif diff --git a/src/lib/marble/IconChooserDialog.cpp b/src/lib/marble/IconChooserDialog.cpp new file mode 100644 --- /dev/null +++ b/src/lib/marble/IconChooserDialog.cpp @@ -0,0 +1,122 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2016 Akshat Tandon +// + +#include "IconChooserDialog.h" +#include "IconChooserModel.h" + +#include +#include + + + +namespace Marble { + +class IconChooserDialogPrivate { +public: + IconChooserDialog *m_parent; + + QString m_iconPath; + + IconChooserModel *m_model; + + IconChooserDialogPrivate( IconChooserDialog* parent ); + + void initializeIconListView( ); + + void handleIconSelection( const QModelIndex &index ); + + void customIcon(); + + void updateButtonState(); + +}; + +IconChooserDialogPrivate::IconChooserDialogPrivate( IconChooserDialog* parent ) + : m_parent(parent), + m_iconPath(), + m_model(new IconChooserModel(parent)) +{ + //does nothing +} + +void IconChooserDialogPrivate::initializeIconListView() +{ + m_model->addIcon("Star", ":/marble/bookmarks/star.png" ); + m_model->addIcon("Annotation", ":/marble/bookmarks/annotation.png" ); + m_model->addIcon("Green Flag", ":/marble/bookmarks/flag.png" ); + m_model->addIcon("Red Flag", ":/marble/bookmarks/red_flag.png" ); + m_parent->iconsListView->setModel(m_model); + m_parent->iconsListView->setEditTriggers( QAbstractItemView::NoEditTriggers ); + m_parent->connect( m_parent->iconsListView, + SIGNAL(clicked(QModelIndex)), + m_parent, SLOT(handleIconSelection(QModelIndex)) ); + m_parent->connect( m_parent->customButton, + SIGNAL(clicked()), + m_parent, SLOT(customIcon()) ); +} + +void IconChooserDialogPrivate::handleIconSelection( const QModelIndex &index ) +{ + if( !index.isValid() ) { + return; + } + m_iconPath = m_model->data(index, Qt::UserRole).toString(); + updateButtonState(); +} + +void IconChooserDialogPrivate::customIcon() +{ + const QString filename = QFileDialog::getOpenFileName( m_parent, + QObject::tr( "Open Icon" ), + QString(), + QObject::tr( "All Supported Files (*.png)" ) ); + if( !filename.isNull() ) + { + m_model->addIcon("Custom Icon", filename ); + m_parent->iconsListView->selectionModel()->clear(); + m_iconPath = ""; + updateButtonState(); + } + +} + +void IconChooserDialogPrivate::updateButtonState() +{ + bool const hasIconSelection = !m_parent->iconsListView->selectionModel()->selectedIndexes().isEmpty(); + m_parent->buttonBox->button(QDialogButtonBox::Ok)->setEnabled( hasIconSelection ); +} + +IconChooserDialog::IconChooserDialog( QWidget *parent ) + :QDialog(parent), + d(new IconChooserDialogPrivate(this)) +{ + setupUi( this ); + d->initializeIconListView(); + d->updateButtonState(); +} + +const QString& IconChooserDialog::iconPath() const +{ + return d->m_iconPath; + +} + +IconChooserDialog::~IconChooserDialog() +{ + delete d; + +} + +} + + + + +#include "moc_IconChooserDialog.cpp" diff --git a/src/lib/marble/IconChooserDialog.ui b/src/lib/marble/IconChooserDialog.ui new file mode 100644 --- /dev/null +++ b/src/lib/marble/IconChooserDialog.ui @@ -0,0 +1,88 @@ + + + UiIconChooserDialog + + + true + + + + 0 + 0 + 289 + 253 + + + + Choose Icon - Marble + + + + 0 + 0 + + + + + + + + + + + + + + Custom + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + + + buttonBox + accepted() + UiIconChooserDialog + accept() + + + 59 + 24 + + + 144 + 126 + + + + + buttonBox + rejected() + UiIconChooserDialog + reject() + + + 59 + 24 + + + 144 + 126 + + + + + diff --git a/src/lib/marble/IconChooserModel.h b/src/lib/marble/IconChooserModel.h new file mode 100644 --- /dev/null +++ b/src/lib/marble/IconChooserModel.h @@ -0,0 +1,38 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2016 Akshat Tandon + +#ifndef ICONCHOOSERMODEL_H +#define ICONCHOOSERMODEL_H + +#include + +namespace Marble +{ +class IconChooserModelPrivate; + + +class IconChooserModel : public QAbstractListModel +{ +public: + IconChooserModel(QObject* parent = 0); + ~IconChooserModel(); + int rowCount(const QModelIndex &parent = QModelIndex() ) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); + void addIcon(const QString &name, const QString &path ); + +private: + IconChooserModelPrivate* const d; + friend class IconChooserModelPrivate; + +}; + +} + +#endif // BRANCHFILTERPROXYMODEL_H diff --git a/src/lib/marble/IconChooserModel.cpp b/src/lib/marble/IconChooserModel.cpp new file mode 100644 --- /dev/null +++ b/src/lib/marble/IconChooserModel.cpp @@ -0,0 +1,115 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2016 Akshat Tandon +// + +#include "IconChooserDialog.h" +#include "IconChooserModel.h" +#include "MarbleDirs.h" +#include "MarbleDebug.h" +#include "MarbleModel.h" + +#include + + +namespace Marble { + +class IconChooserModelPrivate { +public: + IconChooserModel *m_parent; + QStringList m_name; + QStringList m_path; + + IconChooserModelPrivate( IconChooserModel* parent ); +}; + +IconChooserModelPrivate::IconChooserModelPrivate( IconChooserModel *parent ) + : m_parent(parent) , + m_name(), + m_path() +{ + +} + +IconChooserModel::IconChooserModel(QObject *parent) + :QAbstractListModel(parent) , + d( new IconChooserModelPrivate( this ) ) +{ +} + +int IconChooserModel::rowCount(const QModelIndex &parent ) const +{ + Q_UNUSED(parent) //To prevent warning + return d->m_name.size(); +} + +QVariant IconChooserModel::data(const QModelIndex &index, int role ) const +{ + if (!index.isValid()) + return QVariant(); + + int row = index.row(); + if (row >= d->m_name.size()) + return QVariant(); + + QPixmap icon(d->m_path.at(row)); + icon = icon.scaled( QSize(16,16), Qt::KeepAspectRatio, Qt::SmoothTransformation ); + + switch(role) + { + case Qt::DisplayRole: + return QVariant(d->m_name.at(row)); + break; + + case Qt::DecorationRole: + if(!icon.isNull()) + { + return QVariant(icon); + } + break; + + case Qt::UserRole: + return QVariant(d->m_path.at(row)); + break; + + + default: + return QVariant(); + } + return QVariant(); +} + +void IconChooserModel::addIcon(const QString &name, const QString &path ) +{ + insertRows(rowCount(), 1, QModelIndex()); + d->m_path[rowCount() - 1] = path; + d->m_name[rowCount() - 1] = name; + endInsertRows(); +} + +bool IconChooserModel::insertRows(int position, int rows, const QModelIndex &index ) +{ + Q_UNUSED(index) //To prevent warning + beginInsertRows(QModelIndex(), position, position+rows-1); + for (int row = 0; row < rows; ++row) { + d->m_path.insert(position, ""); + d->m_name.insert(position, ""); + } + return true; +} + +IconChooserModel::~IconChooserModel() +{ + delete d; +} + +} + + + + diff --git a/src/lib/marble/PlacemarkEditHeader.cpp b/src/lib/marble/PlacemarkEditHeader.cpp --- a/src/lib/marble/PlacemarkEditHeader.cpp +++ b/src/lib/marble/PlacemarkEditHeader.cpp @@ -8,6 +8,7 @@ // Copyright 2014 Mikhail Ivchenko +#include "IconChooserDialog.h" #include "PlacemarkEditHeader.h" #include "ui_PlacemarkEditHeader.h" @@ -216,16 +217,18 @@ void PlacemarkEditHeaderPrivate::loadIconFile() { - const QString filename = QFileDialog::getOpenFileName( q, - QObject::tr( "Open File" ), - QString(), - QObject::tr( "All Supported Files (*.png)" ) ); - if ( filename.isNull() ) { + QPointer dialog = new IconChooserDialog; + + if ( dialog->exec() == QDialog::Accepted ) { + setIconLink(dialog->iconPath()); + iconLinkButton->setIcon( QIcon(dialog->iconPath()) ); + delete dialog; + + } + else { + delete dialog; return; } - - setIconLink(filename); - iconLinkButton->setIcon( QIcon(filename) ); } bool PlacemarkEditHeaderPrivate::positionVisible() const diff --git a/src/lib/marble/libmarble.qrc b/src/lib/marble/libmarble.qrc --- a/src/lib/marble/libmarble.qrc +++ b/src/lib/marble/libmarble.qrc @@ -103,4 +103,11 @@ htmlfeatures/bootstrap.min.css htmlfeatures/bootstrap.inc + + ../../../data/bitmaps/bookmark.png + ../../../data/bitmaps/annotation.png + ../../../data/bitmaps/flag.png + ../../../data/bitmaps/redflag_32.png + ../../../data/bitmaps/manned_landing.png +