Skip to content

Commit bbcd4a1

Browse files
committed
Renamer 1.3 (Mar / 08 / 2009)
* Rebased Renamer to the Qt framework * Unicode characters now properly supported * Implemented basic status and error reporting
1 parent b81a04f commit bbcd4a1

File tree

7 files changed

+281
-405
lines changed

7 files changed

+281
-405
lines changed

listwidget.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <QtGui>
2+
3+
#include "listwidget.h"
4+
5+
cListWidget::cListWidget(QWidget *parent) : QTableWidget(parent)
6+
{
7+
#ifdef Q_OS_WIN32
8+
rxPath = new QRegExp(tr("^/(.*/)([^/]+)$"));
9+
#else
10+
rxPath = new QRegExp(tr("^(.*/)([^/]+)$"));
11+
#endif
12+
13+
QStringList labels;
14+
labels << tr("Filename") << tr("Path");
15+
16+
setAcceptDrops(true);
17+
setAlternatingRowColors(true);
18+
setColumnCount(2);
19+
setEditTriggers(QAbstractItemView::NoEditTriggers);
20+
setHorizontalHeaderLabels(labels);
21+
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
22+
setSelectionBehavior(QAbstractItemView::SelectRows);
23+
setShowGrid(false);
24+
setTabKeyNavigation(false);
25+
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
26+
27+
horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
28+
horizontalHeader()->setHighlightSections(false);
29+
horizontalHeader()->setStretchLastSection(true);
30+
resizeColumnsToContents();
31+
verticalHeader()->hide();
32+
}
33+
34+
void cListWidget::removeAll()
35+
{
36+
setRowCount(0);
37+
resizeColumnsToContents();
38+
resizeRowsToContents();
39+
horizontalHeader()->setStretchLastSection(true);
40+
}
41+
42+
void cListWidget::removeSelected()
43+
{
44+
int i, size = rowCount();
45+
for (i = 0; i < size; ++i) {
46+
if (item(i, 0)->isSelected()) {
47+
removeRow(i);
48+
--i;
49+
--size;
50+
} // if
51+
} // for
52+
}
53+
54+
void cListWidget::dragEnterEvent(QDragEnterEvent *event)
55+
{
56+
event->acceptProposedAction();
57+
}
58+
59+
void cListWidget::dragMoveEvent(QDragMoveEvent *event)
60+
{
61+
event->acceptProposedAction();
62+
}
63+
64+
void cListWidget::dragLeaveEvent(QDragLeaveEvent *event)
65+
{
66+
event->accept();
67+
}
68+
69+
void cListWidget::dropEvent(QDropEvent *event)
70+
{
71+
const QMimeData *mimeData = event->mimeData();
72+
73+
if (mimeData->hasUrls()) {
74+
QList<QUrl> urlList = mimeData->urls();
75+
int row;
76+
for (int i = 0; i < urlList.size(); ++i) {
77+
if (rxPath->indexIn(urlList.at(i).path()) < 0)
78+
continue;
79+
row = rowCount();
80+
insertRow(row);
81+
setItem(row, 0, new QTableWidgetItem(rxPath->cap(2)));
82+
setItem(row, 1, new QTableWidgetItem(rxPath->cap(1)));
83+
} // for
84+
} // if
85+
resizeColumnsToContents();
86+
resizeRowsToContents();
87+
horizontalHeader()->setStretchLastSection(true);
88+
89+
event->acceptProposedAction();
90+
}

listwidget.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef LISTWIDGET_H
2+
#define LISTWIDGET_H
3+
4+
#include <QTableWidget>
5+
6+
class QMimeData;
7+
8+
class cListWidget : public QTableWidget
9+
{
10+
Q_OBJECT
11+
12+
public:
13+
cListWidget(QWidget *parent = 0);
14+
15+
public slots:
16+
void removeAll();
17+
void removeSelected();
18+
19+
protected:
20+
void dragEnterEvent(QDragEnterEvent *event);
21+
void dragMoveEvent(QDragMoveEvent *event);
22+
void dragLeaveEvent(QDragLeaveEvent *event);
23+
void dropEvent(QDropEvent *event);
24+
25+
private:
26+
QRegExp *rxPath;
27+
};
28+
29+
#endif // LISTWIDGET_H

0 commit comments

Comments
 (0)