File: multipleselect.cc

package info (click to toggle)
splay 0.9.5.2-14
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 848 kB
  • ctags: 1,479
  • sloc: cpp: 7,680; sh: 330; makefile: 35
file content (168 lines) | stat: -rw-r--r-- 2,996 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Sound Player

   Copyright (C) 1997 by Jung woo-jae */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>

#include "multipleselect.h"

MFile::~MFile()
{
  free((void *)str);
}

MSelect::MSelect(QWidget *parent,const char *name) : QTableView(parent,name)
{
  currentselectnum=1;
  setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
  setLineWidth(2);
  setBackgroundColor(white);
  setNumCols(1);
  setNumRows(1);
  setCellWidth(230);
  setCellHeight(20);
  setTableFlags(Tbl_vScrollBar |
		Tbl_clipCellPainting |
		Tbl_smoothScrolling);
  resize(400,200);

  filelist=new QList<MFile>;
  filelist->setAutoDelete(TRUE);
  Clearfilelist();
  Donefilelist();
}

MSelect::~MSelect()
{
  delete filelist;
}

void MSelect::Clearfilelist()
{
  filelist->clear();
  listnumber=0;
}

void MSelect::Appendfilelist(const char *str)
{
  filelist->append(new MFile(str));
  listnumber++;
}

void MSelect::Donefilelist(void)
{
  setNumRows(listnumber);
  selectednumber=0;
  currentfileindex=0;
}

const char* MSelect::Cellstring(int fileindex)
{
  return ((filelist->at(fileindex))->string());
}

int MSelect::IsSelected(int fileindex)
{
  return ((filelist->at(fileindex))->IsSelected());
}

void MSelect::Select(int fileindex,bool select)
{
  int selectnum=0;

  if(IsSelected(fileindex))selectednumber--;

  if(select)
  {
    selectnum=currentselectnum++;
    selectednumber++;
  }
  (filelist->at(fileindex))->Select(selectnum);
}

void MSelect::paintCell(QPainter* p,int fileindex,int)
{
  int w=cellWidth(0);
  int h=cellHeight(fileindex);
  int x2=w-1;
  int y2=h-1;

  if(fileindex==currentfileindex)
  {
    if(hasFocus())p->drawRect(0,0,x2,y2);
    else
    {
      p->setPen(DotLine);
      p->drawRect(0,0,x2,y2);
      p->setPen(SolidLine);
    }
  }

  if(IsSelected(fileindex))
  {
    QBrush brush(black);

    p->fillRect(0+2,0+2,x2-2*2,y2-2*2,brush);
    p->setPen(white);
  }
  else
  {
    p->setPen(white);
    p->drawRect(0+2,0+2,x2-2*2,y2-2*2);
    p->setPen(black);
  }
  p->drawText(0+2,0+2,x2-2*2,y2-2*2,AlignRight,Cellstring(fileindex));
}


void MSelect::mousePressEvent(QMouseEvent* e)
{
  int oldfileindex=currentfileindex;
  QPoint clickedPos=e->pos();

  currentfileindex=findRow(clickedPos.y());

  if(currentfileindex>=0 && currentfileindex<listnumber)
  {
    Select(currentfileindex,IsSelected(currentfileindex)==0);

    updateCell(oldfileindex,0);
    updateCell(currentfileindex,0);

    emit clicked();
  }
}

void MSelect::mouseDoubleClickEvent(QMouseEvent *e)
{
  int oldfileindex=currentfileindex;
  QPoint clickedPos=e->pos();

  currentfileindex=findRow(clickedPos.y());

  if(currentfileindex>=0 && currentfileindex<listnumber)
  {
    Select(currentfileindex,true);

    updateCell(oldfileindex,0);
    updateCell(currentfileindex,0);

    emit doubleclicked();
  }
}

void MSelect::focusInEvent(QFocusEvent*)
{
  updateCell(currentfileindex,0);
}    


void MSelect::focusOutEvent(QFocusEvent*)
{
  updateCell(currentfileindex,0);
}