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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/***************************************************************************
* Project TUPI: Magia 2D *
* Project Contact: info@maefloresta.com *
* Project Website: http://www.maefloresta.com *
* Project Leader: Gustav Gonzalez <info@maefloresta.com> *
* *
* Developers: *
* 2010: *
* Gustavo Gonzalez / xtingray *
* *
* KTooN's versions: *
* *
* 2006: *
* David Cuadrado *
* Jorge Cuadrado *
* 2003: *
* Fernado Roldan *
* Simena Dinas *
* *
* Copyright (C) 2010 Gustav Gonzalez - http://www.maefloresta.com *
* License: *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "tuplistprojectdialog.h"
#include "treelistwidget.h"
#include "treewidgetsearchline.h"
#include "tdebug.h"
#include <QToolButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QPushButton>
#include <QLabel>
struct TupListProjectDialog::Private
{
QTreeWidget *works;
QTreeWidget *contributions;
QList<QString> workList;
QList<QString> contribList;
QList<QString> authors;
int index;
QString filename;
QString owner;
bool isMine;
};
TupListProjectDialog::TupListProjectDialog(int works, int contributions, const QString &serverName) : QDialog(), k(new Private)
{
setWindowIcon(QIcon(QPixmap(THEME_DIR + "icons/open.png")));
setWindowTitle(tr("Projects List from Server") + " - [ " + serverName + " ]");
setModal(true);
QVBoxLayout *layout = new QVBoxLayout(this);
setLayout(layout);
if (works > 0) {
k->works = tree(true);
connect(k->works, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(updateWorkTree()));
connect(k->works, SIGNAL(itemSelectionChanged()), this, SLOT(updateWorkTree()));
connect(k->works, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(execAccept(QTreeWidgetItem *, int)));
}
if (contributions > 0) {
k->contributions = tree(false);
connect(k->contributions, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(updateContribTree()));
connect(k->contributions, SIGNAL(itemSelectionChanged()), this, SLOT(updateContribTree()));
connect(k->contributions, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(execAccept(QTreeWidgetItem *, int)));
}
QHBoxLayout *search = new QHBoxLayout;
TreeWidgetSearchLine *searchLine = 0;
QToolButton *button = new QToolButton;
button->setIcon(QIcon(THEME_DIR + "icons/zoom.png"));
QLabel *worksLabel = new QLabel(tr("My works:"));
QLabel *contribLabel = new QLabel(tr("My contributions:"));
if (works > 0 && contributions > 0) {
QList<QTreeWidget *> trees;
trees << k->works << k->contributions;
searchLine = new TreeWidgetSearchLine(this, trees);
search->addWidget(searchLine);
search->addWidget(button);
layout->addLayout(search);
layout->addWidget(worksLabel);
layout->addWidget(k->works);
layout->addWidget(contribLabel);
layout->addWidget(k->contributions);
} else if (works > 0) {
searchLine = new TreeWidgetSearchLine(this, k->works);
search->addWidget(searchLine);
search->addWidget(button);
layout->addLayout(search);
layout->addWidget(worksLabel);
layout->addWidget(k->works);
} else if (contributions > 0) {
searchLine = new TreeWidgetSearchLine(this, k->contributions);
search->addWidget(searchLine);
search->addWidget(button);
layout->addLayout(search);
layout->addWidget(contribLabel);
layout->addWidget(k->contributions);
}
connect(button, SIGNAL(clicked()), searchLine, SLOT(clear()));
//----
QHBoxLayout *buttons = new QHBoxLayout;
QPushButton *accept = new QPushButton(tr("OK"));
accept->setDefault(true);
QPushButton *cancel = new QPushButton("Cancel");
connect(accept, SIGNAL(clicked ()), this, SLOT(accept()));
connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
buttons->addWidget(cancel);
buttons->addWidget(accept);
layout->addLayout(buttons);
setMinimumWidth(615);
k->index = 0;
}
TupListProjectDialog::~TupListProjectDialog()
{
}
QTreeWidget *TupListProjectDialog::tree(bool myWorks)
{
QTreeWidget *tree = new QTreeWidget;
tree->setFixedHeight(120);
if (myWorks)
tree->setHeaderLabels(QStringList() << tr("Name") << tr("Description") << tr("Date"));
else
tree->setHeaderLabels(QStringList() << tr("Name") << tr("Author") << tr("Description") << tr("Date"));
tree->header()->show();
if (myWorks) {
tree->setColumnWidth(0, 200);
tree->setColumnWidth(1, 250);
tree->setColumnWidth(2, 55);
} else {
tree->setColumnWidth(0, 150);
tree->setColumnWidth(1, 100);
tree->setColumnWidth(2, 200);
tree->setColumnWidth(3, 55);
}
return tree;
}
void TupListProjectDialog::addWork(const QString &filename, const QString &name, const QString &description, const QString &date)
{
k->workList.append(filename);
QTreeWidgetItem *item = new QTreeWidgetItem(k->works);
item->setText(0, name);
item->setText(1, description);
item->setText(2, date);
if (k->index == 0) {
k->isMine = true;
k->works->setCurrentItem(item);
k->filename = filename;
}
k->index++;
}
void TupListProjectDialog::addContribution(const QString &filename, const QString &name, const QString &author, const QString &description, const QString &date)
{
k->contribList.append(filename);
k->authors.append(author);
QTreeWidgetItem *item = new QTreeWidgetItem(k->contributions);
item->setText(0, name);
item->setText(1, author);
item->setText(2, description);
item->setText(3, date);
}
QString TupListProjectDialog::projectID() const
{
return k->filename;
}
QString TupListProjectDialog::owner() const
{
return k->owner;
}
void TupListProjectDialog::execAccept(QTreeWidgetItem *item, int index)
{
Q_UNUSED(item);
if (index >= 0)
accept();
}
void TupListProjectDialog::updateWorkTree()
{
if (k->works->hasFocus()) {
if (k->contribList.size() > 0)
k->contributions->clearSelection();
int index = k->works->currentIndex().row();
k->filename = k->workList.at(index);
k->isMine = true;
}
}
void TupListProjectDialog::updateContribTree()
{
if (k->contributions->hasFocus()) {
if (k->workList.size() > 0)
k->works->clearSelection();
int index = k->contributions->currentIndex().row();
k->isMine = false;
k->filename = k->contribList.at(index);
k->owner = k->authors.at(index);
}
}
bool TupListProjectDialog::workIsMine()
{
return k->isMine;
}
|