00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CHANNELPALETTE_H
00018 #define CHANNELPALETTE_H
00019
00020
00021 #include <qvariant.h>
00022 #include <qwidget.h>
00023 #include <qvbox.h>
00024 #include <qiconview.h>
00025 #include <qdict.h>
00026 #include <qptrlist.h>
00027 #include <qmap.h>
00028 #include <qdragobject.h>
00029 #include <qlabel.h>
00030 #include <qcursor.h>
00031
00032
00033 #include "channelgroupview.h"
00034 #include "channeliconview.h"
00035
00036
00037 #include <iostream>
00038 using namespace std;
00039
00040
00041 class QIconView;
00042 class QIconViewItem;
00043 class ChannelColors;
00044 class SpaceWidget;
00045
00053 class ChannelPalette : public QScrollView
00054 {
00055 Q_OBJECT
00056
00057 public:
00058
00059 enum PaletteType {DISPLAY=0,SPIKE=1};
00060
00069 ChannelPalette(PaletteType type,QColor backgroundColor,bool edition,QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
00070
00071
00072
00073 ~ChannelPalette();
00074
00080 void createChannelLists(ChannelColors* channelColors,QMap<int, QValueList<int> >* groupsChannels,QMap<int,int>* channelsGroups);
00081
00085 void selectChannels(const QValueList<int>& selectedChannels);
00086
00088 void reset();
00089
00091 const QValueList<int> selectedChannels();
00092
00094 void changeBackgroundColor(QColor color);
00095
00100 const QValueList<int> getShowHideChannels(bool showStatus);
00101
00106 inline const QMap<int,bool>getSkipStatus(){return channelsSkipStatus;};
00107
00111 class ChannelIconItem : public QIconViewItem{
00112
00113 public:
00114 inline ChannelIconItem(QIconView* parent,const QString& text,const QPixmap& icon):
00115 QIconViewItem(parent,text,icon){};
00116
00117 inline ChannelIconItem(QIconView* parent,QIconViewItem* after,const QString& text,const QPixmap& icon):
00118 QIconViewItem(parent,after,text,icon){};
00119
00120 virtual inline int compare(QIconViewItem* item) const{
00121 if(key().toInt() < item->key().toInt()) return -1;
00122 else if(key().toInt() == item->key().toInt()) return 0;
00123 else return 1;
00124 };
00125 };
00126
00127
00128 public slots:
00129 virtual void changeColor(QIconViewItem* item,bool single = true);
00132 void createGroup();
00133 void setGreyScale(bool grey);
00135 void deleteEmptyGroups();
00136 void selectAllChannels();
00137 void deselectAllChannels();
00139 void slotChannelsMoved(QString targetGroup,QIconViewItem* after);
00141 void slotChannelsMoved(const QValueList<int>& channelIds,QString sourceGroup,QIconViewItem* after);
00142 void trashChannelsMovedAround(const QValueList<int>& channelIds,QString afterId,bool beforeFirst);
00143 void discardChannels();
00144 void discardChannels(const QValueList<int>& channelsToDiscard);
00145 void discardChannels(const QValueList<int>& channelsToDiscard,QString afterId,bool beforeFirst);
00146 void discardSpikeChannels();
00147 void showChannels();
00148 void hideChannels();
00149 void hideUnselectAllChannels();
00150 void updateShowHideStatus(const QValueList<int>&channelIds,bool showStatus);
00151 void updateSkipStatus(const QMap<int,bool>& skipStatus);
00152 void updateSkipStatus(const QValueList<int>&channelIds,bool skipStatus);
00153 void updateColor(const QValueList<int>& channelIds);
00154 void updateColor(int channelId);
00159 void updateGroupColor(int channelId);
00160 void applyGroupColor(PaletteType paletteType);
00161 void applyCustomColor();
00162 void setEditMode(bool edition);
00163 void groupToMove(int sourceId,int targetId,int start, int destination);
00164 void removeChannelsFromTrash(const QValueList<int>& channelIds);
00165 void slotMousePressWoModificators(QString sourceGroup);
00166 inline void selectionTool(){
00167 emit channelsSelected(selectedChannels());
00168 };
00169
00170 protected slots:
00171 virtual void slotRightPressed(QIconViewItem* item);
00172 virtual void slotMousePressed(int button,QIconViewItem* item);
00173 void slotMousePressed(QString sourceGroupName);
00174 virtual void slotMidButtonPressed(QString sourceGroupId);
00175 virtual void slotClickRedraw();
00176 virtual void languageChange();
00177 virtual void createGroup(int id);
00178 virtual void setChannelLists();
00179 virtual void resizeEvent(QResizeEvent* event);
00180 virtual void drawContents(QPainter* painter);
00181 inline void slotDragLabeltMoved(QPoint position){ensureVisible(position.x(),position.y());};
00182
00183 signals:
00184 void singleChangeColor(int selectedChannel);
00185 void groupChangeColor(int groupId);
00186
00187 void updateShownChannels(const QValueList<int>& shownChannels);
00188 void updateHideChannels(const QValueList<int>& hiddenChannels);
00189 void paletteResized(int parentWidth,int labelSize);
00190 void channelsDiscarded(const QValueList<int>& discarded);
00191 void setDragAndDrop(bool dragAndDrop);
00192 void groupModified();
00193 void channelsMovedToTrash(const QValueList<int>&channelIds,QString afterId,bool beforeFirst);
00194 void channelsMovedAroundInTrash(const QValueList<int>& channelsToDiscard,QString afterId,bool beforeFirst);
00195 void channelsRemovedFromTrash(const QValueList<int>& channelIds);
00196 void channelsSelected(const QValueList<int>& selectedChannels);
00197
00198 private:
00200 ChannelColors* channelColors;
00201
00203 QColor backgroundColor;
00204
00206 bool isInSelectItems;
00207
00208 QVBox* verticalContainer;
00209
00211 QDict<ChannelIconView> iconviewDict;
00212
00214 QDict<ChannelGroupView> channelGroupViewDict;
00215
00217 SpaceWidget* spaceWidget;
00218
00221 QMap<int,int>* channelsGroups;
00222
00226 QMap<int, QValueList<int> >* groupsChannels;
00227
00228 int labelSize;
00229
00231 bool greyScale;
00232
00234 bool isGroupToRemove;
00235
00237 PaletteType type;
00238
00240 QMap<int,bool> channelsShowHideStatus;
00241
00243 bool edit;
00244
00246 QString selected;
00247
00249 QMap<int,bool> channelsSkipStatus;
00250
00252 QMap<QString,bool> selectionStatus;
00253
00254
00255
00260 void updateShowHideStatus(bool showStatus);
00261
00271 void drawItem(QPainter& painter,QPixmap* pixmap,QColor color,bool show,bool skip);
00272
00274 void moveTrashesToBottom();
00275
00277 void moveChannels(const QValueList<int>& channelIds,QString sourceGroup,QIconViewItem* after);
00278
00280 void moveChannels(const QValueList<int>& channelIds,QString sourceGroup,QString targetGroup);
00281
00285 void trashChannels(int destinationGroup);
00286
00290 void moveChannels(int targetGroup);
00291
00295 int createEmptyGroup();
00296 };
00297
00300 class SpaceWidget : public QWidget{
00301 Q_OBJECT
00302 public:
00303 inline SpaceWidget(QWidget* parent,bool drag):QWidget(parent),drag(drag){
00304 setAcceptDrops(TRUE);
00305 };
00306
00307 inline virtual void dropEvent(QDropEvent* event){
00308 if(event->source() == 0 || !drag){
00309 event->ignore();
00310 return;
00311 }
00312
00313 QString information;
00314 if(QTextDrag::decode(event,information)){
00315 int groupSource = information.section("-",0,0).toInt();
00316 int start = information.section("-",1,1).toInt();
00317
00318 emit dropLabel(groupSource,-2,start,QWidget::mapToGlobal(event->pos()).y());
00319 }
00320 };
00321
00322 inline virtual void dragEnterEvent(QDragEnterEvent* event){
00323 if(event->source() == 0 || !drag){
00324 event->ignore();
00325 return;
00326 }
00327 event->accept(QTextDrag::canDecode(event));
00328 };
00329
00330 public slots:
00331 inline void setDragAndDrop(bool dragDrop){drag = dragDrop;};
00332
00333 signals:
00334 void dropLabel(int sourceId,int targetId,int start, int destination);
00335
00336 private:
00338 bool drag;
00339
00340 };
00341
00346 class GroupLabel : public QLabel{
00347 Q_OBJECT
00348 public:
00349 inline GroupLabel(const QString& text,QWidget* parent,const char* name = 0,WFlags f = 0):
00350 QLabel(text,parent,name,f){};
00351
00352 signals:
00353 void middleClickOnLabel(QString sourceId);
00354 void leftClickOnLabel(QString sourceId);
00355
00356 protected:
00357 virtual inline void mousePressEvent(QMouseEvent* e){
00358 if(e->button() == QMouseEvent::LeftButton){
00359
00360 QPoint firstClick = QWidget::mapToGlobal(e->pos());
00361 QString information = parent()->name();
00362 information.append(QString("-%1").arg(firstClick.y()));
00363 QDragObject* drag = new QTextDrag(information,this);
00364 drag->dragMove();
00365
00366 emit leftClickOnLabel(parent()->name());
00367 }
00368 if(e->button() == QMouseEvent::MidButton){
00369 emit middleClickOnLabel(parent()->name());
00370 }
00371 };
00372 };
00373
00374 #endif // CHANNELPALETTE_H