#include <KLocalizedString>
// Qt toolkit headers.
+#include <QFileDialog>
#include <QPushButton>
// Construct the class.
-AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr), icon(favoriteIcon)
+AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr)
{
// Set the window title.
setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark"));
addBookmarkDialogUi.setupUi(this);
// Get handles for the widgets.
- QGraphicsView *favoriteIconGraphicsViewPointer = addBookmarkDialogUi.favoriteIconGraphicsView;
+ defaultFavoriteIconRadioButtonPointer = addBookmarkDialogUi.defaultFavoriteIconRadioButton;
+ customFavoriteIconRadioButtonPointer = addBookmarkDialogUi.customFavoriteIconRadioButton;
bookmarkNamePointer = addBookmarkDialogUi.bookmarkNameLineEdit;
bookmarkUrlPointer = addBookmarkDialogUi.bookmarkUrlLineEdit;
+ QPushButton *browseButtonPointer = addBookmarkDialogUi.browseButton;
QDialogButtonBox *dialogButtonBoxPointer = addBookmarkDialogUi.dialogButtonBox;
- // Create a graphics scene.
- QGraphicsScene *favoriteIconGraphicsScenePointer = new QGraphicsScene(this);
-
- // Set the graphics scene.
- favoriteIconGraphicsViewPointer->setScene(favoriteIconGraphicsScenePointer);
-
- // Set the background of the graphics view to be the same as the window
- favoriteIconGraphicsViewPointer->setBackgroundRole(QPalette::Window);
-
- // Add the MIME type icon to the scene.
- favoriteIconGraphicsScenePointer->addPixmap(favoriteIcon.pixmap(32, 32));
+ // Set the default favorite icon.
+ defaultFavoriteIconRadioButtonPointer->setIcon(favoriteIcon);
// Populate the line edits.
bookmarkNamePointer->setText(bookmarkName);
bookmarkUrlPointer->setText(bookmarkUrl);
- // Scroll the the beginning of the line edits.
+ // Scroll to the beginning of the line edits.
bookmarkNamePointer->setCursorPosition(0);
bookmarkUrlPointer->setCursorPosition(0);
addBookmarkButtonPointer->setIcon(QIcon::fromTheme("list-add"));
// Connect the buttons.
+ connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(browse()));
connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(addBookmark()));
connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
}
void AddBookmarkDialog::addBookmark()
{
+ // Get the favorite icon.
+ QIcon favoriteIcon = defaultFavoriteIconRadioButtonPointer->isChecked() ? defaultFavoriteIconRadioButtonPointer->icon() : customFavoriteIconRadioButtonPointer->icon();
+
+ // Create a bookmark struct.
+ BookmarkStruct *bookmarkStructPointer = new BookmarkStruct;
+
+ // Populate the bookmark struct.
+ bookmarkStructPointer->bookmarkName = bookmarkNamePointer->text();
+ bookmarkStructPointer->bookmarkUrl = bookmarkUrlPointer->text();
+ bookmarkStructPointer->favoriteIcon = favoriteIcon;
+
// Add the bookmark.
- BookmarksDatabase::addBookmark(bookmarkNamePointer->text(), bookmarkUrlPointer->text(), icon);
+ BookmarksDatabase::addBookmark(bookmarkStructPointer);
+
+ // Update the list of bookmarks in the menu and toolbar.
+ emit bookmarkAdded();
// Close the dialog.
close();
}
+void AddBookmarkDialog::browse()
+{
+ // Get an image file string from the user.
+ QString imageFileString = QFileDialog::getOpenFileName(this, tr("Favorite Icon Image"), QDir::homePath(),
+ tr("Image Files — *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.svg (*.bmp *.gif *.jpg *.jpeg *.png *.svg);;All Files (*)"));
+
+ // Check to see if an image file string was returned. This will be empty if the user selected cancel.
+ if (!imageFileString.isEmpty())
+ {
+ // Set the custom favorite icon.
+ customFavoriteIconRadioButtonPointer->setIcon(QIcon(imageFileString));
+
+ // Check the custom favorite icon radio button.
+ customFavoriteIconRadioButtonPointer->setChecked(true);
+ }
+}