From f5f23ff4b233339c2e99685de40fa127fec0ceba Mon Sep 17 00:00:00 2001 From: ars_goldendict Date: Sun, 26 Apr 2009 13:16:30 +0000 Subject: [PATCH] reorganization of Groups dialog (unstable - needs to be checked) --- src/flags.qrc | 502 +++++++++++++++++++++--------------------- src/flags/en.png | Bin 0 -> 599 bytes src/flags/uk.png | Bin 0 -> 446 bytes src/groups.cc | 60 +++++ src/groups.hh | 5 +- src/groups.ui | 403 ++++++++++++++++++++------------- src/groups_widgets.cc | 271 ++++++++++++++++++++--- src/groups_widgets.hh | 37 +++- src/langcoder.cc | 21 +- src/langcoder.hh | 6 +- 10 files changed, 851 insertions(+), 454 deletions(-) create mode 100644 src/flags/en.png create mode 100644 src/flags/uk.png diff --git a/src/flags.qrc b/src/flags.qrc index 0825af3d..333a51f2 100644 --- a/src/flags.qrc +++ b/src/flags.qrc @@ -1,252 +1,254 @@ - - flags/wiki.png - flags/ad.png - flags/ae.png - flags/af.png - flags/ag.png - flags/ai.png - flags/al.png - flags/am.png - flags/an.png - flags/ao.png - flags/ar.png - flags/as.png - flags/at.png - flags/au.png - flags/aw.png - flags/ax.png - flags/az.png - flags/ba.png - flags/bb.png - flags/bd.png - flags/be.png - flags/bf.png - flags/bg.png - flags/bh.png - flags/bi.png - flags/bj.png - flags/bm.png - flags/bn.png - flags/bo.png - flags/br.png - flags/bs.png - flags/bt.png - flags/bv.png - flags/bw.png - flags/by.png - flags/bz.png - flags/ca.png - flags/catalonia.png - flags/cc.png - flags/cd.png - flags/cf.png - flags/cg.png - flags/ch.png - flags/ci.png - flags/ck.png - flags/cl.png - flags/cm.png - flags/cn.png - flags/co.png - flags/cr.png - flags/cs.png - flags/cu.png - flags/cv.png - flags/cx.png - flags/cy.png - flags/cz.png - flags/de.png - flags/dj.png - flags/dk.png - flags/dm.png - flags/do.png - flags/dz.png - flags/ec.png - flags/ee.png - flags/eg.png - flags/eh.png - flags/england.png - flags/er.png - flags/es.png - flags/et.png - flags/europeanunion.png - flags/fam.png - flags/fi.png - flags/fj.png - flags/fk.png - flags/fm.png - flags/fo.png - flags/fr.png - flags/ga.png - flags/gb.png - flags/gd.png - flags/ge.png - flags/gf.png - flags/gh.png - flags/gi.png - flags/gl.png - flags/gm.png - flags/gn.png - flags/gp.png - flags/gq.png - flags/gr.png - flags/gs.png - flags/gt.png - flags/gu.png - flags/gw.png - flags/gy.png - flags/hk.png - flags/hm.png - flags/hn.png - flags/hr.png - flags/ht.png - flags/hu.png - flags/id.png - flags/ie.png - flags/il.png - flags/in.png - flags/io.png - flags/iq.png - flags/ir.png - flags/is.png - flags/it.png - flags/jm.png - flags/jo.png - flags/jp.png - flags/ke.png - flags/kg.png - flags/kh.png - flags/ki.png - flags/km.png - flags/kn.png - flags/kp.png - flags/kr.png - flags/kw.png - flags/ky.png - flags/kz.png - flags/la.png - flags/lb.png - flags/lc.png - flags/li.png - flags/lk.png - flags/lr.png - flags/ls.png - flags/lt.png - flags/lu.png - flags/lv.png - flags/ly.png - flags/ma.png - flags/mc.png - flags/md.png - flags/me.png - flags/mg.png - flags/mh.png - flags/mk.png - flags/ml.png - flags/mm.png - flags/mn.png - flags/mo.png - flags/mp.png - flags/mq.png - flags/mr.png - flags/ms.png - flags/mt.png - flags/mu.png - flags/mv.png - flags/mw.png - flags/mx.png - flags/my.png - flags/mz.png - flags/na.png - flags/nc.png - flags/ne.png - flags/nf.png - flags/ng.png - flags/ni.png - flags/nl.png - flags/no.png - flags/np.png - flags/nr.png - flags/nu.png - flags/nz.png - flags/om.png - flags/pa.png - flags/pe.png - flags/pf.png - flags/pg.png - flags/ph.png - flags/pk.png - flags/pl.png - flags/pm.png - flags/pn.png - flags/pr.png - flags/ps.png - flags/pt.png - flags/pw.png - flags/py.png - flags/qa.png - flags/re.png - flags/ro.png - flags/rs.png - flags/ru.png - flags/rw.png - flags/sa.png - flags/sb.png - flags/scotland.png - flags/sc.png - flags/sd.png - flags/se.png - flags/sg.png - flags/sh.png - flags/si.png - flags/sj.png - flags/sk.png - flags/sl.png - flags/sm.png - flags/sn.png - flags/so.png - flags/sr.png - flags/st.png - flags/sv.png - flags/sy.png - flags/sz.png - flags/tc.png - flags/td.png - flags/tf.png - flags/tg.png - flags/th.png - flags/tj.png - flags/tk.png - flags/tl.png - flags/tm.png - flags/tn.png - flags/to.png - flags/tr.png - flags/tt.png - flags/tv.png - flags/tw.png - flags/tz.png - flags/ua.png - flags/ug.png - flags/um.png - flags/us.png - flags/uy.png - flags/uz.png - flags/va.png - flags/vc.png - flags/ve.png - flags/vg.png - flags/vi.png - flags/vn.png - flags/vu.png - flags/wales.png - flags/wf.png - flags/ws.png - flags/ye.png - flags/yt.png - flags/za.png - flags/zm.png - flags/zw.png - + + flags/wiki.png + flags/ad.png + flags/ae.png + flags/af.png + flags/ag.png + flags/ai.png + flags/al.png + flags/am.png + flags/an.png + flags/ao.png + flags/ar.png + flags/as.png + flags/at.png + flags/au.png + flags/aw.png + flags/ax.png + flags/az.png + flags/ba.png + flags/bb.png + flags/bd.png + flags/be.png + flags/bf.png + flags/bg.png + flags/bh.png + flags/bi.png + flags/bj.png + flags/bm.png + flags/bn.png + flags/bo.png + flags/br.png + flags/bs.png + flags/bt.png + flags/bv.png + flags/bw.png + flags/by.png + flags/bz.png + flags/ca.png + flags/catalonia.png + flags/cc.png + flags/cd.png + flags/cf.png + flags/cg.png + flags/ch.png + flags/ci.png + flags/ck.png + flags/cl.png + flags/cm.png + flags/cn.png + flags/co.png + flags/cr.png + flags/cs.png + flags/cu.png + flags/cv.png + flags/cx.png + flags/cy.png + flags/cz.png + flags/de.png + flags/dj.png + flags/dk.png + flags/dm.png + flags/do.png + flags/dz.png + flags/ec.png + flags/ee.png + flags/eg.png + flags/eh.png + flags/england.png + flags/er.png + flags/es.png + flags/et.png + flags/europeanunion.png + flags/fam.png + flags/fi.png + flags/fj.png + flags/fk.png + flags/fm.png + flags/fo.png + flags/fr.png + flags/ga.png + flags/gb.png + flags/gd.png + flags/ge.png + flags/gf.png + flags/gh.png + flags/gi.png + flags/gl.png + flags/gm.png + flags/gn.png + flags/gp.png + flags/gq.png + flags/gr.png + flags/gs.png + flags/gt.png + flags/gu.png + flags/gw.png + flags/gy.png + flags/hk.png + flags/hm.png + flags/hn.png + flags/hr.png + flags/ht.png + flags/hu.png + flags/id.png + flags/ie.png + flags/il.png + flags/in.png + flags/io.png + flags/iq.png + flags/ir.png + flags/is.png + flags/it.png + flags/jm.png + flags/jo.png + flags/jp.png + flags/ke.png + flags/kg.png + flags/kh.png + flags/ki.png + flags/km.png + flags/kn.png + flags/kp.png + flags/kr.png + flags/kw.png + flags/ky.png + flags/kz.png + flags/la.png + flags/lb.png + flags/lc.png + flags/li.png + flags/lk.png + flags/lr.png + flags/ls.png + flags/lt.png + flags/lu.png + flags/lv.png + flags/ly.png + flags/ma.png + flags/mc.png + flags/md.png + flags/me.png + flags/mg.png + flags/mh.png + flags/mk.png + flags/ml.png + flags/mm.png + flags/mn.png + flags/mo.png + flags/mp.png + flags/mq.png + flags/mr.png + flags/ms.png + flags/mt.png + flags/mu.png + flags/mv.png + flags/mw.png + flags/mx.png + flags/my.png + flags/mz.png + flags/na.png + flags/nc.png + flags/ne.png + flags/nf.png + flags/ng.png + flags/ni.png + flags/nl.png + flags/no.png + flags/np.png + flags/nr.png + flags/nu.png + flags/nz.png + flags/om.png + flags/pa.png + flags/pe.png + flags/pf.png + flags/pg.png + flags/ph.png + flags/pk.png + flags/pl.png + flags/pm.png + flags/pn.png + flags/pr.png + flags/ps.png + flags/pt.png + flags/pw.png + flags/py.png + flags/qa.png + flags/re.png + flags/ro.png + flags/rs.png + flags/ru.png + flags/rw.png + flags/sa.png + flags/sb.png + flags/scotland.png + flags/sc.png + flags/sd.png + flags/se.png + flags/sg.png + flags/sh.png + flags/si.png + flags/sj.png + flags/sk.png + flags/sl.png + flags/sm.png + flags/sn.png + flags/so.png + flags/sr.png + flags/st.png + flags/sv.png + flags/sy.png + flags/sz.png + flags/tc.png + flags/td.png + flags/tf.png + flags/tg.png + flags/th.png + flags/tj.png + flags/tk.png + flags/tl.png + flags/tm.png + flags/tn.png + flags/to.png + flags/tr.png + flags/tt.png + flags/tv.png + flags/tw.png + flags/tz.png + flags/ua.png + flags/ug.png + flags/um.png + flags/us.png + flags/uy.png + flags/uz.png + flags/va.png + flags/vc.png + flags/ve.png + flags/vg.png + flags/vi.png + flags/vn.png + flags/vu.png + flags/wales.png + flags/wf.png + flags/ws.png + flags/ye.png + flags/yt.png + flags/za.png + flags/zm.png + flags/zw.png + flags/en.png + flags/uk.png + diff --git a/src/flags/en.png b/src/flags/en.png new file mode 100644 index 0000000000000000000000000000000000000000..ff701e19f6d2c0658fb23b1d94124cba4ce60851 GIT binary patch literal 599 zcmV-d0;v6oP)U(k2*|8J(R-+sudaynhucHbwAMTnor{mwqO^w7JHzaBsT z{O^B8RYf5+LvDs&KmRKVd78=o{`1#HTiEo_OolaGleS)G+IQ#sUI`b*pv<`1zCJ=H0jd{{2S>p`ri%{LsXJ%FbMS z$#S`6f|?OG!^Jxczkf6Q`UNF{l0Sd`ad7zm>({^EzyAS6{{CgrkluOb3l1A>ZU2~A zK+FZ=zkmP!`TOVhpFbzBzFaPmD2$N3;+$pK?>zdet`f0002ovPDHLkV1gy;I?Vt8 literal 0 HcmV?d00001 diff --git a/src/flags/uk.png b/src/flags/uk.png new file mode 100644 index 0000000000000000000000000000000000000000..09563a21941f2a94c937d43aceda1aa546246302 GIT binary patch literal 446 zcmV;v0YUzWP))t0eYh-DxnQ(+0I@JIfmA>F`X8wD?>`2h#NWRRzyE`zA&Pzh5tt#% z!^rUCA3y+sZ1@LM1hf`pHc0ia|NsB|1uKPX0CRu;1-SztfLMSo`wOxir1}rsY$VlC z667idh7Sw?0mQ-}a!Q0#;n&}vAb0=!_Zy@WNd5!6=O2ju7s{65Vq=gx0uVrqe;+b1 z$mIY3|KLBvF9x7j{{!v#g_UGtQhI;<6hHv607H@yECdWlR7EJN!LomVp$!l~APvkQ z4p0cL2#YobhQA>6hXEjfKpL3-19eKmL_s!=;22W8vpcount(); ui.renameGroup->setEnabled( en ); +// ui.emptyGroup->setEnabled( en ); ui.removeGroup->setEnabled( en ); + ui.removeGroups->setEnabled( en ); + + ui.tbAddDictsToGroup->setEnabled( en ); + ui.tbRemoveDictsFromGroup->setEnabled( en ); } void Groups::addNew() @@ -78,6 +93,38 @@ void Groups::renameCurrent() ui.groups->renameCurrentGroup( name ); } +//void Groups::emptyCurrent() +//{ +// int current = ui.groups->currentIndex(); +// +// if ( current < 0 || QMessageBox::question( this, tr( "Empty group contents" ), +// tr( "Are you sure you want to remove all the dictionaries from this group?" ), +// QMessageBox::Yes, QMessageBox::Cancel ) != QMessageBox::Yes ) +// return; +// +// ui.groups->emptyCurrentGroup(); +//} + +void Groups::addDictsToCurrentGroup() +{ + int current = ui.groups->currentIndex(); + + if ( current >= 0 ) + { + ui.groups->getCurrentModel()->addSelectedUniqueFromModel( ui.dictionaries->selectionModel() ); + } +} + +void Groups::removeDictsFromCurrentGroup() +{ + int current = ui.groups->currentIndex(); + + if ( current >= 0 ) + { + ui.groups->getCurrentModel()->removeSelectedRows( ui.groups->getCurrentSelectionModel() ); + } +} + void Groups::removeCurrent() { int current = ui.groups->currentIndex(); @@ -90,3 +137,16 @@ void Groups::removeCurrent() countChanged(); } } + +void Groups::removeAll() +{ + int current = ui.groups->currentIndex(); + + if ( current >= 0 && QMessageBox::question( this, tr( "Remove all groups" ), + tr( "Are you sure you want to remove all the groups?" ), + QMessageBox::Yes, QMessageBox::Cancel ) == QMessageBox::Yes ) + { + ui.groups->removeAllGroups(); + countChanged(); + } +} diff --git a/src/groups.hh b/src/groups.hh index 5d3a9262..d5087fb1 100644 --- a/src/groups.hh +++ b/src/groups.hh @@ -30,10 +30,13 @@ private: void countChanged(); private slots: - void addNew(); void renameCurrent(); + //void emptyCurrent(); + void addDictsToCurrentGroup(); + void removeDictsFromCurrentGroup(); void removeCurrent(); + void removeAll(); }; #endif diff --git a/src/groups.ui b/src/groups.ui index 12f5ee69..29d7920a 100644 --- a/src/groups.ui +++ b/src/groups.ui @@ -1,158 +1,245 @@ - - Groups - - - Qt::WindowModal - - - - 0 - 0 - 726 - 535 - - - - Groups - - - - - - - - - - Dictionaries available: - - - - - - - - - - - - - - Groups: - - - - - - - QTabWidget::North - - - Qt::ElideRight - - - - Tab 2 - - - - - - - - - - &Add group - - - - - - - Re&name group - - - - - - - &Remove group - - - - - - - - - - - - - Drag&drop dictionaries to and from the groups, move them inside the groups, reorder the groups using your mouse. - - - true - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - DictListWidget - QListWidget -
groups_widgets.hh
-
- - DictGroupsWidget - QTabWidget -
groups_widgets.hh
- 1 -
-
- - - - buttons - accepted() - Groups - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttons - rejected() - Groups - reject() - - - 316 - 260 - - - 286 - 274 - - - - -
+ + + Groups + + + Qt::WindowModal + + + + 0 + 0 + 784 + 505 + + + + Groups + + + + + + + + Dictionaries available + + + + + + + + + + + + + + + 32 + 32 + + + + > + + + + + + + + 32 + 32 + + + + < + + + + + + + + + User groups + + + + + + + + Create a new dictionary group + + + &Add group + + + + + + + Change current group's name + + + Re&name group + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Remove group + + + &Remove group + + + + + + + Remove all groups + + + Remove all groups + + + + + + + + + QTabWidget::North + + + QTabWidget::Rounded + + + Qt::ElideRight + + + false + + + + Tab 2 + + + + + + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + Drag & drop dictionaries to and from the groups, move them inside the groups, reorder the groups using your mouse. + + + true + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + DictListWidget + QListWidget +
groups_widgets.hh
+
+ + DictGroupsWidget + QTabWidget +
groups_widgets.hh
+ 1 +
+
+ + + + buttons + accepted() + Groups + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttons + rejected() + Groups + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/groups_widgets.cc b/src/groups_widgets.cc index 9bbf8b26..11664b21 100644 --- a/src/groups_widgets.cc +++ b/src/groups_widgets.cc @@ -79,9 +79,80 @@ std::vector< sptr< Dictionary::Class > > const & return dictionaries; } +void DictListModel::removeSelectedRows( QItemSelectionModel * source ) +{ + if ( !source ) + return; + + QModelIndexList rows = source->selectedRows(); + + if ( !rows.count() ) + return; + + for ( int i = rows.count()-1; i >= 0; --i ) + { + dictionaries.erase( dictionaries.begin() + rows.at( i ).row() ); + } + + reset(); +} + +void DictListModel::addSelectedUniqueFromModel( QItemSelectionModel * source ) +{ + if ( !source ) + return; + + QModelIndexList rows = source->selectedRows(); + + if ( !rows.count() ) + return; + + const DictListModel * baseModel = dynamic_cast< const DictListModel * > ( source->model() ); + if ( !baseModel ) + return; + + QVector< Dictionary::Class * > list; + QVector< Dictionary::Class * > dicts; + for ( int i = 0; i < dictionaries.size(); i++ ) + dicts.append( dictionaries.at( i ).get() ); + + for ( int i = 0; i < rows.count(); i++ ) + { + Dictionary::Class * d = + static_cast< Dictionary::Class * > ( rows.at( i ).internalPointer() ); + + //qDebug() << "rows.at( i ).internalPointer() " << rows.at( i ).internalPointer(); + + if ( !d ) + continue; + +// sptr< Dictionary::Class > s ( d ); +// +// if ( std::find( dictionaries.begin(), dictionaries.end(), s ) == dictionaries.end() ) +// continue; +// +// qDebug() << "std::find "; + + if ( !dicts.contains( d ) ) + list.append( d ); + + //list.push_back( s ); + } + + if ( list.empty() ) + return; + +// qDebug() << "list " << list.size(); + + for ( int i = 0; i < list.size(); i++ ) + dictionaries.push_back( sptr< Dictionary::Class > ( list.at( i ) ) ); + + reset(); +} + Qt::ItemFlags DictListModel::flags( QModelIndex const & index ) const { - Qt::ItemFlags defaultFlags = QAbstractListModel::flags( index ); + Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index ); if (index.isValid()) return Qt::ItemIsDragEnabled | defaultFlags; @@ -101,20 +172,69 @@ QVariant DictListModel::data( QModelIndex const & index, int role ) const if ( !item ) return QVariant(); - switch ( role ) + switch ( index.column() ) { - case Qt::DisplayRole : - return QString::fromUtf8( item->getName().c_str() ); -// + QString(" lang: %1 %2").arg( langCoder.decode(item->getLangFrom()), -// langCoder.decode(item->getLangTo()) ); + case 0: + { + switch ( role ) + { + case Qt::DisplayRole : + return QString::fromUtf8( item->getName().c_str() ); + // + QString(" lang: %1 %2").arg( langCoder.decode(item->getLangFrom()), + // langCoder.decode(item->getLangTo()) ); - case Qt::EditRole : - return QString::fromUtf8( item->getId().c_str() ); + case Qt::EditRole : + return QString::fromUtf8( item->getId().c_str() ); - case Qt::DecorationRole: - return item->getIcon(); + case Qt::DecorationRole: + return item->getIcon(); + + default:; + } + + break; + } + + case 1: + { + switch ( role ) + { + case Qt::DisplayRole : + return LangCoder::decode( item->getLangFrom() ).left( 3 ); + + case Qt::EditRole : + break; + + case Qt::DecorationRole: + return LangCoder::icon( item->getLangFrom() ); + + default:; + } + + break; + } + + case 2: + { + switch ( role ) + { + case Qt::DisplayRole : + return LangCoder::decode( item->getLangTo() ).left( 3 ); + + case Qt::EditRole : + break; + + case Qt::DecorationRole: + return LangCoder::icon( item->getLangTo() ); + + default:; + } + + break; + } default:; + } return QVariant(); @@ -141,7 +261,7 @@ bool DictListModel::removeRows( int row, int count, beginRemoveRows( parent, row, row + count - 1 ); dictionaries.erase( dictionaries.begin() + row, - dictionaries.begin() + row + count ); + count == INT_MAX ? dictionaries.end() : dictionaries.begin() + row + count ); endRemoveRows(); return true; @@ -160,45 +280,80 @@ bool DictListModel::setData( QModelIndex const & index, const QVariant & value, return true; } - if ( role == Qt::EditRole ) - { - Config::Group g; - - g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) ); - - Instances::Group i( g, *allDicts ); - - if ( i.dictionaries.size() == 1 ) - { - // Found that dictionary - dictionaries[ index.row() ] = i.dictionaries.front(); - - emit dataChanged( index, index ); - - return true; - } - } +// if ( role == Qt::EditRole ) +// { +// Config::Group g; +// +// g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) ); +// +// Instances::Group i( g, *allDicts ); +// +// if ( i.dictionaries.size() == 1 ) +// { +// // Found that dictionary +// dictionaries[ index.row() ] = i.dictionaries.front(); +// +// emit dataChanged( index, index ); +// +// return true; +// } +// } return false; } Qt::DropActions DictListModel::supportedDropActions() const { - return Qt::MoveAction; + return 0; //Qt::MoveAction; +} + +QModelIndex DictListModel::index( int row, int column, const QModelIndex &parent ) const +{ + return createIndex( row, column, dictionaries.at( row ).get() ); +} + +QModelIndex DictListModel::parent( const QModelIndex & child ) const +{ + return QModelIndex(); +} + +QVariant DictListModel::headerData ( int section, Qt::Orientation orientation, int role ) const +{ + if ( role == Qt::DisplayRole ) + { + switch ( section ) + { + case 0: return tr( "Dictionary" ); + case 1: return tr( "Source" ); + case 2: return tr( "Target" ); + default:; + } + } + + return QAbstractItemModel::headerData( section, orientation, role ); } /// DictListWidget -DictListWidget::DictListWidget( QWidget * parent ): QListView( parent ), +DictListWidget::DictListWidget( QWidget * parent ): QTreeView( parent ), model( this ) { setModel( &model ); setSelectionMode( ExtendedSelection ); - setDragEnabled( true ); - setAcceptDrops( true ); - setDropIndicatorShown( true ); + setDragEnabled( false ); + setAcceptDrops( false ); + setDropIndicatorShown( false ); + + setRootIsDecorated( false ); + setItemsExpandable( false ); +// setSortingEnabled( true ); + + header()->setAlternatingRowColors( true ); + header()->setResizeMode( QHeaderView::ResizeToContents ); +// header()->setSortIndicatorShown( true ); +// header()->setSortIndicator( 1, Qt::AscendingOrder ); } DictListWidget::~DictListWidget() @@ -281,6 +436,32 @@ Config::Groups DictGroupsWidget::makeGroups() const return result; } +DictListModel * DictGroupsWidget::getCurrentModel() const +{ + int current = currentIndex(); + + if ( current >= 0 ) + { + DictGroupWidget * w = ( DictGroupWidget * ) widget( current ); + return w->getModel(); + } + + return 0; +} + +QItemSelectionModel * DictGroupsWidget::getCurrentSelectionModel() const +{ + int current = currentIndex(); + + if ( current >= 0 ) + { + DictGroupWidget * w = ( DictGroupWidget * ) widget( current ); + return w->getSelectionModel(); + } + + return 0; +} + void DictGroupsWidget::addNewGroup( QString const & name ) { if ( !allDicts ) @@ -317,6 +498,17 @@ void DictGroupsWidget::renameCurrentGroup( QString const & name ) setTabText( current, escapeAmps( name ) ); } +void DictGroupsWidget::emptyCurrentGroup() +{ + int current = currentIndex(); + + if ( current >= 0 ) + { + DictGroupWidget * w = ( DictGroupWidget * ) widget( current ); + w->getModel()->removeRows( ); + } +} + void DictGroupsWidget::removeCurrentGroup() { int current = currentIndex(); @@ -328,3 +520,14 @@ void DictGroupsWidget::removeCurrentGroup() delete w; } } + +void DictGroupsWidget::removeAllGroups() +{ + while ( count() ) + { + QWidget * w = widget( 0 ); + removeTab( 0 ); + delete w; + } +} + diff --git a/src/groups_widgets.hh b/src/groups_widgets.hh index c2f04db8..c3a12987 100644 --- a/src/groups_widgets.hh +++ b/src/groups_widgets.hh @@ -6,20 +6,20 @@ // Various custom widgets used in the Groups dialog -#include +#include #include "config.hh" #include "dictionary.hh" #include /// A model to be projected into the view, according to Qt's MVC model -class DictListModel: public QAbstractListModel +class DictListModel: public QAbstractItemModel { Q_OBJECT public: DictListModel( QWidget * parent ): - QAbstractListModel( parent ), isSource( false ), allDicts( 0 ) + QAbstractItemModel( parent ), isSource( false ), allDicts( 0 ) {} /// Populates the current model with the given dictionaries. This is @@ -32,12 +32,20 @@ public: /// Returns the dictionaries the model currently has listed std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const; + void removeSelectedRows( QItemSelectionModel * source ); + void addSelectedUniqueFromModel( QItemSelectionModel * source ); + Qt::ItemFlags flags( QModelIndex const &index ) const; int rowCount( QModelIndex const & parent ) const; + int columnCount( QModelIndex const & parent ) const { return 3; } QVariant data( QModelIndex const & index, int role ) const; - bool insertRows( int row, int count, const QModelIndex & parent ); - bool removeRows( int row, int count, const QModelIndex & parent ); + bool insertRows( int row, int count, const QModelIndex & parent = QModelIndex() ); + bool removeRows( int row = 0, int count = INT_MAX, const QModelIndex & parent = QModelIndex() ); bool setData( QModelIndex const & index, const QVariant & value, int role ); + QModelIndex index( int row, int column, + const QModelIndex &parent = QModelIndex() ) const; + QModelIndex parent( const QModelIndex &child ) const; + QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; Qt::DropActions supportedDropActions() const; @@ -50,7 +58,7 @@ private: /// This widget is for dictionaries' lists, it handles drag-n-drop operations /// with them etc. -class DictListWidget: public QListView +class DictListWidget: public QTreeView { Q_OBJECT public: @@ -67,6 +75,8 @@ public: /// Returns the dictionaries the widget currently has listed std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const; + DictListModel * getModel() + { return & model; } private: @@ -90,6 +100,12 @@ public: /// (it is known by the containing tab widget only), it is returned as empty. Config::Group makeGroup() const; + DictListModel * getModel() const + { return ui.dictionaries->getModel(); } + + QItemSelectionModel * getSelectionModel() const + { return ui.dictionaries->selectionModel(); } + private: Ui::DictGroupWidget ui; unsigned groupId; @@ -117,12 +133,21 @@ public: /// Changes the name of the currently chosen group, if any, to the given one void renameCurrentGroup( QString const & ); + void emptyCurrentGroup(); + /// Removes the currently chosen group, if any void removeCurrentGroup(); + /// Removes all the groups + void removeAllGroups(); + /// Creates groups from what is currently set up Config::Groups makeGroups() const; + DictListModel * getCurrentModel() const; + + QItemSelectionModel * getCurrentSelectionModel() const; + private: unsigned nextId; diff --git a/src/langcoder.cc b/src/langcoder.cc index 13c1cdfd..ddf9ec71 100644 --- a/src/langcoder.cc +++ b/src/langcoder.cc @@ -14,21 +14,36 @@ LangCoder::LangCoder() const LangCode &lc = LangCodes[i]; if (lc.lang[0] == 0) break; - //ls.order = i; - //ls.icon = QIcon(":/flags/" + QString(lc.code) + ".png"); codeMap[code2toInt(lc.code)] = i; } } QString LangCoder::decode(quint32 code) { - // temp! if (langCoder.codeMap.contains(code)) return LangCodes[langCoder.codeMap[code]].lang; return QString(); } +QIcon LangCoder::icon(quint32 code) +{ + if (langCoder.codeMap.contains(code)) + { + const LangCode &lc = LangCodes[ langCoder.codeMap[ code ] ]; +// QString flag_id( lc.code ); +// if (flag_id == "en") +// flag_id = "gb"; +// else +// if (flag_id == "uk") +// flag_id = "ua"; + + return QIcon( ":/flags/" + QString( lc.code) + ".png" ); + } + + return QIcon(); +} + LangStruct LangCoder::langStruct(quint32 code) { LangStruct ls; diff --git a/src/langcoder.hh b/src/langcoder.hh index bfb42c22..4bd31d03 100644 --- a/src/langcoder.hh +++ b/src/langcoder.hh @@ -237,6 +237,8 @@ public: /// Returns decoded name of language or empty string if not found. static QString decode(quint32 code); + /// Returns icon for language or empty string if not found. + static QIcon icon(quint32 code); //const QMap& codes() { return codeMap; } @@ -246,12 +248,12 @@ public: // bool CheckCode(QString &code); -protected: +private: QMap codeMap; // LangStruct dummyLS; }; -extern LangCoder langCoder; +//extern LangCoder langCoder; ///////////////////////////////////////////////////////////////////////////////