diff options
| author | kamalpreetgrewal <grewalkamal005@gmail.com> | 2016-06-04 14:32:59 +0000 |
|---|---|---|
| committer | kamalpreetgrewal <grewalkamal005@gmail.com> | 2016-06-04 14:32:59 +0000 |
| commit | 46bff7b31a99784086c5f5589956e647c862e944 (patch) | |
| tree | 3427ea78c69021a0a82f4dd5cf68655d40f9021a /src/ui | |
| parent | Fix for bug on previous commit about guides lock (diff) | |
| download | inkscape-46bff7b31a99784086c5f5589956e647c862e944.tar.gz inkscape-46bff7b31a99784086c5f5589956e647c862e944.zip | |
Register style dialog with support to add selector
(bzr r14949.1.1)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/dialog/dialog-manager.cpp | 3 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 113 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.h | 69 |
4 files changed, 187 insertions, 0 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 587974b90..4be3fa3d2 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -99,6 +99,7 @@ set(ui_SRC dialog/print-colors-preview-dialog.cpp dialog/print.cpp dialog/spellcheck.cpp + dialog/styledialog.cpp dialog/svg-fonts-dialog.cpp dialog/swatches.cpp dialog/symbols.cpp @@ -240,6 +241,7 @@ set(ui_SRC dialog/print-colors-preview-dialog.h dialog/print.h dialog/spellcheck.h + dialog/styledialog.h dialog/svg-fonts-dialog.h dialog/swatches.h dialog/symbols.h diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 49853277c..4bb5215fd 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -60,6 +60,7 @@ #include "ui/dialog/svg-fonts-dialog.h" #include "ui/dialog/objects.h" #include "ui/dialog/tags.h" +#include "ui/dialog/styledialog.h" namespace Inkscape { namespace UI { @@ -128,6 +129,7 @@ DialogManager::DialogManager() { registerFactory("Swatches", &create<SwatchesPanel, FloatingBehavior>); registerFactory("TileDialog", &create<ArrangeDialog, FloatingBehavior>); registerFactory("Symbols", &create<SymbolsDialog, FloatingBehavior>); + registerFactory("StyleDialog", &create<StyleDialog, FloatingBehavior>); #if HAVE_POTRACE registerFactory("Trace", &create<TraceDialog, FloatingBehavior>); @@ -167,6 +169,7 @@ DialogManager::DialogManager() { registerFactory("Swatches", &create<SwatchesPanel, DockBehavior>); registerFactory("TileDialog", &create<ArrangeDialog, DockBehavior>); registerFactory("Symbols", &create<SymbolsDialog, DockBehavior>); + registerFactory("StyleDialog", &create<StyleDialog, DockBehavior>); #if HAVE_POTRACE registerFactory("Trace", &create<TraceDialog, DockBehavior>); diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp new file mode 100644 index 000000000..7e555ddb2 --- /dev/null +++ b/src/ui/dialog/styledialog.cpp @@ -0,0 +1,113 @@ +#include "styledialog.h" +#include "widgets/icon.h" +#include "verbs.h" +#include "sp-object.h" +#include "selection.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +void StyleDialog::_styleButton(Gtk::Button& btn, char const* iconName, + char const* tooltip) +{ + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show(child); + btn.add(*manage(Glib::wrap(child))); + btn.set_relief(Gtk::RELIEF_NONE); + btn.set_tooltip_text (tooltip); +} + +/** + * Constructor + * A treeview and a set of two buttons are added to the dialog. _addSelector + * adds selectors to treeview. Currently, delete button is disabled. + */ +StyleDialog::StyleDialog() : + UI::Widget::Panel("", "/dialogs/style", SP_VERB_DIALOG_STYLE), + _desktop(0) +{ + set_size_request(200, 200); + add(_mainBox); + + _mainBox.pack_start(_scrolledWindow, Gtk::PACK_EXPAND_WIDGET); + _treeView.set_headers_visible(false); + _scrolledWindow.add(_treeView); + _scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + + _store = Gtk::ListStore::create(_mColumns); + _treeView.set_model(_store); + _treeView.append_column("Selector Number", _mColumns._selectorNumber); + _treeView.append_column("Selector Name", _mColumns._selectorLabel); + + Gtk::Button* create = manage( new Gtk::Button() ); + _styleButton(*create, "list-add", "Add a new CSS Selector"); + create->signal_clicked().connect(sigc::mem_fun(*this, + &StyleDialog::_addSelector)); + + Gtk::Button* del = manage( new Gtk::Button() ); + _styleButton(*del, "list-remove", "Remove a CSS Selector"); + del->set_sensitive(false); + + _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); + + SPDesktop* targetDesktop = getDesktop(); + setDesktop(targetDesktop); +} + +StyleDialog::~StyleDialog() +{ + setDesktop(NULL); +} + +void StyleDialog::setDesktop( SPDesktop* desktop ) +{ + Panel::setDesktop(desktop); + _desktop = Panel::getDesktop(); +} + +void StyleDialog::_addSelector() +{ + Gtk::TreeModel::Row row = *(_store->append()); + + /** + * On clicking '+' button, an entrybox with default text opens up. If an + * object is already selected, 'class' attribute with value in the entry + * is added to the selected object. + */ + Gtk::Dialog *textDialogPtr = new Gtk::Dialog(); + Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); + textDialogPtr->add_button("Add", Gtk::RESPONSE_OK); + textDialogPtr->get_vbox()->pack_start(*textEditPtr, Gtk::PACK_SHRINK); + textEditPtr->set_text("Class1"); + + textDialogPtr->set_size_request(200, 100); + textDialogPtr->show_all(); + int result = textDialogPtr->run(); + static int number = 1; + + switch (result) { + case Gtk::RESPONSE_OK: + textDialogPtr->hide(); + row[_mColumns._selectorNumber] = number; + row[_mColumns._selectorLabel] = textEditPtr->get_text(); + number++; + break; + default: + break; + } + + if (_desktop->selection) { + std::vector<SPObject*> selected = _desktop->getSelection()->list(); + for (int i = 0; i < selected.size(); ++i ) { + SPObject *obj = selected.at(i); + obj->setAttribute("class", textEditPtr->get_text()); + } + } +} + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h new file mode 100644 index 000000000..044737add --- /dev/null +++ b/src/ui/dialog/styledialog.h @@ -0,0 +1,69 @@ +/** @file + * @brief A dialog for CSS selectors + */ +/* Authors: + * Kamalpreet Kaur Grewal + * + * Copyright (C) Kamalpreet Kaur Grewal 2016 <grewalkamal005@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef STYLEDIALOG_H +#define STYLEDIALOG_H + +#include <ui/widget/panel.h> +#include <gtkmm/treeview.h> +#include <gtkmm/liststore.h> +#include <gtkmm/scrolledwindow.h> +#include <gtkmm/dialog.h> + +#include "desktop.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * @brief The StyleDialog class + * A list of CSS selectors will show up in this dialog. + */ + +class StyleDialog : public UI::Widget::Panel +{ +public: + StyleDialog(); + ~StyleDialog(); + + static StyleDialog &getInstance() { return *new StyleDialog(); } + void setDesktop( SPDesktop* desktop); + +private: + void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); + + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumns() + { add(_selectorNumber); add(_selectorLabel); } + Gtk::TreeModelColumn<int> _selectorNumber; + Gtk::TreeModelColumn<Glib::ustring> _selectorLabel; + }; + + SPDesktop* _desktop; + ModelColumns _mColumns; + Gtk::VBox _mainBox; + Gtk::HBox _buttonBox; + Gtk::TreeView _treeView; + Glib::RefPtr<Gtk::ListStore> _store; + Gtk::ScrolledWindow _scrolledWindow; + + // Signal handlers + void _addSelector(); +}; + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape + +#endif // STYLEDIALOG_H |
