~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/qg_layerwidget.h

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
 
6
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
7
**
 
8
**
 
9
** This file is free software; you can redistribute it and/or modify
 
10
** it under the terms of the GNU General Public License as published by
 
11
** the Free Software Foundation; either version 2 of the License, or
 
12
** (at your option) any later version.
 
13
**
 
14
** This program is distributed in the hope that it will be useful,
 
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
** GNU General Public License for more details.
 
18
**
 
19
** You should have received a copy of the GNU General Public License
 
20
** along with this program; if not, write to the Free Software
 
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
#ifndef QG_LAYERWIDGET_H
 
28
#define QG_LAYERWIDGET_H
 
29
 
 
30
#include <QWidget>
 
31
#include <QIcon>
 
32
#include <QAbstractTableModel>
 
33
 
 
34
#include "rs_layerlistlistener.h"
 
35
#include "rs_layerlist.h"
 
36
 
 
37
class QG_ActionHandler;
 
38
class QTableView;
 
39
class QLineEdit;
 
40
 
 
41
/**
 
42
 * Implementation of a model to use in QG_LayerWidget
 
43
 */
 
44
class QG_LayerModel: public QAbstractTableModel {
 
45
public:
 
46
    enum {
 
47
        VISIBLE,
 
48
        LOCKED,
 
49
        HelpLayer,
 
50
        NAME,
 
51
        LAST
 
52
    };
 
53
    QG_LayerModel(QObject * parent = 0);
 
54
    ~QG_LayerModel();
 
55
    Qt::ItemFlags flags ( const QModelIndex & /*index*/ ) const {
 
56
            return Qt::ItemIsSelectable|Qt::ItemIsEnabled;}
 
57
    int columnCount(const QModelIndex &/*parent*/) const {return LAST;}
 
58
    int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
 
59
    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
 
60
    QModelIndex parent ( const QModelIndex & index ) const;
 
61
    QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
 
62
    void setLayerList(RS_LayerList* ll);
 
63
    RS_Layer *getLayer( int row );
 
64
    QModelIndex getIndex (RS_Layer * lay);
 
65
 
 
66
private:
 
67
    QList<RS_Layer*> listLayer;
 
68
    QIcon layerVisible;
 
69
    QIcon layerHidden;
 
70
    QIcon layerDefreeze;
 
71
    QIcon layerFreeze;
 
72
    QIcon helpLayer;
 
73
};
 
74
 
 
75
 
 
76
/**
 
77
 * This is the Qt implementation of a widget which can view a
 
78
 * layer list and provides a user interface for basic layer actions.
 
79
 */
 
80
class QG_LayerWidget: public QWidget, public RS_LayerListListener {
 
81
    Q_OBJECT
 
82
 
 
83
public:
 
84
    QG_LayerWidget(QG_ActionHandler* ah, QWidget* parent,
 
85
                   const char* name=0, Qt::WindowFlags f = 0);
 
86
    ~QG_LayerWidget();
 
87
 
 
88
    void setLayerList(RS_LayerList* layerList, bool showByBlock);
 
89
 
 
90
    void update();
 
91
    void activateLayer(RS_Layer* layer);
 
92
 
 
93
    virtual void layerActivated(RS_Layer* layer) {
 
94
        activateLayer(layer);
 
95
    }
 
96
    virtual void layerAdded(RS_Layer* layer) {
 
97
        update();
 
98
        activateLayer(layer);
 
99
    }
 
100
    virtual void layerEdited(RS_Layer*) {
 
101
        update();
 
102
    }
 
103
   virtual void layerRemoved(RS_Layer*) {
 
104
        update();
 
105
        activateLayer(layerList->at(0));
 
106
    }
 
107
    virtual void layerToggled(RS_Layer*) {
 
108
        update();
 
109
    }
 
110
    virtual void layerToggledLock(RS_Layer*) {
 
111
        update();
 
112
    }
 
113
    virtual void layerToggledPrint(RS_Layer*) {
 
114
        update();
 
115
    }
 
116
 
 
117
    QLineEdit* getMatchLayerName() {
 
118
        return matchLayerName;
 
119
    }
 
120
 
 
121
signals:
 
122
    void escape();
 
123
 
 
124
public slots:
 
125
    void slotActivated(QModelIndex layerIdx);
 
126
    void slotUpdateLayerList();
 
127
 
 
128
protected:
 
129
    void contextMenuEvent(QContextMenuEvent *e);
 
130
    virtual void keyPressEvent(QKeyEvent* e);
 
131
 
 
132
private:
 
133
    RS_LayerList* layerList;
 
134
    bool showByBlock;
 
135
    QLineEdit* matchLayerName;
 
136
    QTableView* layerView;
 
137
    QG_LayerModel *layerModel;
 
138
    RS_Layer* lastLayer;   
 
139
    QG_ActionHandler* actionHandler;
 
140
};
 
141
 
 
142
#endif