From afa241bef7476b3bb3dd882434014eeb7b16644e Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 17 Sep 2010 23:26:04 -0700 Subject: Simplify/clarify enabling of individual devices. (bzr r9765) --- src/ui/dialog/input.cpp | 78 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 13 deletions(-) (limited to 'src/ui/dialog/input.cpp') diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index 92a54affb..e7d61e415 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -331,12 +331,14 @@ namespace Dialog { class DeviceModelColumns : public Gtk::TreeModel::ColumnRecord { public: + Gtk::TreeModelColumn toggler; + Gtk::TreeModelColumn expander; Gtk::TreeModelColumn description; - Gtk::TreeModelColumn< Glib::RefPtr > thumbnail; + Gtk::TreeModelColumn > thumbnail; Gtk::TreeModelColumn > device; Gtk::TreeModelColumn mode; - DeviceModelColumns() { add(description); add(thumbnail); add(device); add(mode); } + DeviceModelColumns() { add(toggler), add(expander), add(description); add(thumbnail); add(device); add(mode); } }; static std::map &getModeToString() @@ -390,6 +392,9 @@ private: static void commitCellModeChange(Glib::ustring const &path, Glib::ustring const &newText, Glib::RefPtr store); static void setModeCellString(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter); + static void commitCellStateChange(Glib::ustring const &path, Glib::RefPtr store); + static void setCellStateToggle(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter); + void saveSettings(); void useExtToggled(); @@ -806,24 +811,39 @@ InputDialogImpl::ConfPanel::ConfPanel() : row = *(poppers->append()); row[foo.one] = getModeToString()[Gdk::MODE_WINDOW]; - Gtk::CellRendererCombo *rendr = new Gtk::CellRendererCombo(); - rendr->property_model().set_value(poppers); - rendr->property_text_column().set_value(0); - rendr->property_has_entry() = false; - //Add the TreeView's view columns: + { + Gtk::CellRendererToggle *rendr = new Gtk::CellRendererToggle(); + Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("xx", *rendr); + if (col) { + tree.append_column(*col); + col->set_cell_data_func(*rendr, sigc::ptr_fun(setCellStateToggle)); + rendr->signal_toggled().connect(sigc::bind(sigc::ptr_fun(commitCellStateChange), store)); + } + } + + int expPos = tree.append_column("", getCols().expander); + tree.append_column("I", getCols().thumbnail); tree.append_column("Bar", getCols().description); - Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("X", *rendr); - if (col) { - tree.append_column(*col); - col->set_cell_data_func(*rendr, sigc::ptr_fun(setModeCellString)); - rendr->signal_edited().connect(sigc::bind(sigc::ptr_fun(commitCellModeChange), store)); - rendr->property_editable() = true; + + { + Gtk::CellRendererCombo *rendr = new Gtk::CellRendererCombo(); + rendr->property_model().set_value(poppers); + rendr->property_text_column().set_value(0); + rendr->property_has_entry() = false; + Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("X", *rendr); + if (col) { + tree.append_column(*col); + col->set_cell_data_func(*rendr, sigc::ptr_fun(setModeCellString)); + rendr->signal_edited().connect(sigc::bind(sigc::ptr_fun(commitCellModeChange), store)); + rendr->property_editable() = true; + } } tree.set_enable_tree_lines(); tree.set_headers_visible(false); + tree.set_expander_column( *tree.get_column(expPos - 1) ); setupTree( store, tabletIter ); @@ -874,6 +894,38 @@ void InputDialogImpl::ConfPanel::commitCellModeChange(Glib::ustring const &path, } } +void InputDialogImpl::ConfPanel::setCellStateToggle(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter) +{ + if (iter) { + Gtk::CellRendererToggle *toggle = dynamic_cast(rndr); + if (toggle) { + Glib::RefPtr dev = (*iter)[getCols().device]; + if (dev) { + Gdk::InputMode mode = (*iter)[getCols().mode]; + toggle->set_active(mode != Gdk::MODE_DISABLED); + } else { + toggle->set_active(false); + } + } + } +} + +void InputDialogImpl::ConfPanel::commitCellStateChange(Glib::ustring const &path, Glib::RefPtr store) +{ + Gtk::TreeIter iter = store->get_iter(path); + if (iter) { + Glib::RefPtr dev = (*iter)[getCols().device]; + if (dev) { + Gdk::InputMode mode = (*iter)[getCols().mode]; + if (mode == Gdk::MODE_DISABLED) { + Inkscape::DeviceManager::getManager().setMode( dev->getId(), Gdk::MODE_SCREEN ); + } else { + Inkscape::DeviceManager::getManager().setMode( dev->getId(), Gdk::MODE_DISABLED ); + } + } + } +} + void InputDialogImpl::ConfPanel::saveSettings() { Inkscape::DeviceManager::getManager().saveConfig(); -- cgit v1.2.3 From 3a036468841793a88a70edf9e8245af29f2c17e8 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Wed, 22 Sep 2010 21:23:27 -0700 Subject: Tablet auto-organization and naming. (bzr r9777) --- src/ui/dialog/input.cpp | 154 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 122 insertions(+), 32 deletions(-) (limited to 'src/ui/dialog/input.cpp') diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index e7d61e415..8c98515e9 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -725,6 +726,44 @@ InputDialogImpl::InputDialogImpl() : show_all_children(); } +class TabletTmp { +public: + TabletTmp() {} + + Glib::ustring name; + std::list > devices; +}; + +static Glib::ustring getCommon( std::list const &names ) +{ + Glib::ustring result; + + if ( !names.empty() ) { + size_t pos = 0; + bool match = true; + while ( match ) { + if ( names.begin()->length() > pos ) { + gunichar ch = (*names.begin())[pos]; + for ( std::list::const_iterator it = names.begin(); it != names.end(); ++it ) { + if ( (pos >= it->length()) + || ((*it)[pos] != ch) ) { + match = false; + break; + } + } + if (match) { + result += ch; + pos++; + } + } else { + match = false; + } + } + } + + return result; +} + void InputDialogImpl::setupTree( Glib::RefPtr store, Gtk::TreeIter &tablet ) { std::list > devList = Inkscape::DeviceManager::getManager().getDevices(); @@ -732,48 +771,99 @@ void InputDialogImpl::setupTree( Glib::RefPtr store, Gtk::TreeIt Gtk::TreeModel::Row row = *(store->append()); row[getCols().description] = _("Hardware"); - tablet = store->append(row.children()); - Gtk::TreeModel::Row childrow = *tablet; - childrow[getCols().description] = _("Tablet"); - childrow[getCols().thumbnail] = getPix(PIX_TABLET); + // Let's make some tablets!!! + std::list tablets; + std::set consumed; + // Phase 1 - figure out which tablets are present for ( std::list >::iterator it = devList.begin(); it != devList.end(); ++it ) { Glib::RefPtr dev = *it; if ( dev ) { -// g_message("device: name[%s] source[0x%x] mode[0x%x] cursor[%s] axis count[%d] key count[%d]", dev->getName().c_str(), dev->getSource(), dev->getMode(), -// dev->hasCursor() ? "Yes":"no", dev->getNumAxes(), dev->getNumKeys()); - -// if ( dev->getSource() != Gdk::SOURCE_MOUSE ) { - if ( dev ) { - Gtk::TreeModel::Row deviceRow = *(store->append(childrow.children())); - deviceRow[getCols().description] = dev->getName(); - deviceRow[getCols().device] = dev; - deviceRow[getCols().mode] = dev->getMode(); - switch ( dev->getSource() ) { - case GDK_SOURCE_MOUSE: - deviceRow[getCols().thumbnail] = getPix(PIX_CORE); - break; - case GDK_SOURCE_PEN: - if (deviceRow[getCols().description] == _("pad")) { - deviceRow[getCols().thumbnail] = getPix(PIX_SIDEBUTTONS); - } else { - deviceRow[getCols().thumbnail] = getPix(PIX_TIP); - } - break; - case GDK_SOURCE_CURSOR: - deviceRow[getCols().thumbnail] = getPix(PIX_MOUSE); - break; - case GDK_SOURCE_ERASER: - deviceRow[getCols().thumbnail] = getPix(PIX_ERASER); - break; - default: - ; // nothing + if ( dev->getSource() != Gdk::SOURCE_MOUSE ) { + consumed.insert( dev->getId() ); + if ( tablets.empty() ) { + TabletTmp tmp; + tablets.push_back(tmp); } + tablets.back().devices.push_back(dev); } } else { g_warning("Null device in list"); } } + + // Phase 2 - build a UI for the present devices + for ( std::list::iterator it = tablets.begin(); it != tablets.end(); ++it ) { + tablet = store->append(row.children()); + Gtk::TreeModel::Row childrow = *tablet; + if ( it->name.empty() ) { + // Check to see if we can derive one + std::list names; + for ( std::list >::iterator it2 = it->devices.begin(); it2 != it->devices.end(); ++it2 ) { + names.push_back( (*it2)->getName() ); + } + Glib::ustring common = getCommon(names); + if ( !common.empty() ) { + it->name = common; + } + } + childrow[getCols().description] = it->name.empty() ? _("Tablet") : it->name ; + childrow[getCols().thumbnail] = getPix(PIX_TABLET); + + // Check if there is an eraser we can link to a pen + for ( std::list >::iterator it2 = it->devices.begin(); it2 != it->devices.end(); ++it2 ) { + Glib::RefPtr dev = *it2; + if ( dev->getSource() == Gdk::SOURCE_PEN ) { + for ( std::list >::iterator it3 = it->devices.begin(); it3 != it->devices.end(); ++it3 ) { + Glib::RefPtr dev2 = *it3; + if ( dev2->getSource() == Gdk::SOURCE_ERASER ) { + DeviceManager::getManager().setLinkedTo(dev->getId(), dev2->getId()); + break; // only check the first eraser... for now + } + break; // only check the first pen... for now + } + } + } + + for ( std::list >::iterator it2 = it->devices.begin(); it2 != it->devices.end(); ++it2 ) { + Glib::RefPtr dev = *it2; + Gtk::TreeModel::Row deviceRow = *(store->append(childrow.children())); + deviceRow[getCols().description] = dev->getName(); + deviceRow[getCols().device] = dev; + deviceRow[getCols().mode] = dev->getMode(); + switch ( dev->getSource() ) { + case GDK_SOURCE_MOUSE: + deviceRow[getCols().thumbnail] = getPix(PIX_CORE); + break; + case GDK_SOURCE_PEN: + if (deviceRow[getCols().description] == _("pad")) { + deviceRow[getCols().thumbnail] = getPix(PIX_SIDEBUTTONS); + } else { + deviceRow[getCols().thumbnail] = getPix(PIX_TIP); + } + break; + case GDK_SOURCE_CURSOR: + deviceRow[getCols().thumbnail] = getPix(PIX_MOUSE); + break; + case GDK_SOURCE_ERASER: + deviceRow[getCols().thumbnail] = getPix(PIX_ERASER); + break; + default: + ; // nothing + } + } + } + + for ( std::list >::iterator it = devList.begin(); it != devList.end(); ++it ) { + Glib::RefPtr dev = *it; + if ( dev && (consumed.find( dev->getId() ) == consumed.end()) ) { + Gtk::TreeModel::Row deviceRow = *(store->append(row.children())); + deviceRow[getCols().description] = dev->getName(); + deviceRow[getCols().device] = dev; + deviceRow[getCols().mode] = dev->getMode(); + deviceRow[getCols().thumbnail] = getPix(PIX_CORE); + } + } } else { g_warning("No devices found"); } -- cgit v1.2.3 From 144819c918dc761641c3cb5a490205fb73194ee3 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Wed, 17 Nov 2010 13:12:56 +1100 Subject: Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in all 1074 Vim modelines. The reason for this is that (a) setting the encoding isn't nice, and (b) Vim 7.3 (with modeline enabled) disallows it and pops up an error whenever you open any file with it ("invalid modeline"). Also corrected five deviant modestrings: * src/ui/widget/dock.cpp and src/ui/widget/dock.h: missing colon at the end * src/ui/dialog/tile.cpp: removed gratuitous second colon at the end * src/helper/units-test.h: removed gratuitous space before a colon * share/extensions/export_gimp_palette.py: missing textwidth=99 That's my geekiest commit yet. (bzr r9900) --- src/ui/dialog/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/dialog/input.cpp') diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index 8c98515e9..8f19c90c4 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -1610,4 +1610,4 @@ bool InputDialogImpl::eventSnoop(GdkEvent* event) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3