aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-03-14 20:23:05 +0000
committerGravatar Fabio Bas2010-03-14 20:23:05 +0000
commitf5bfd72f1ad27b81f1efe9f84249c0a8cebf2082 (patch)
treee57346b647319380161bc8fa2ea0a84ff8f344bc /src
parentfix for #745 (diff)
downloadKVIrc-f5bfd72f1ad27b81f1efe9f84249c0a8cebf2082.tar.gz
KVIrc-f5bfd72f1ad27b81f1efe9f84249c0a8cebf2082.tar.bz2
KVIrc-f5bfd72f1ad27b81f1efe9f84249c0a8cebf2082.zip
a lot of fixes for the registered user dialogs, including the ones for #746
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4132 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
-rw-r--r--src/modules/reguser/dialog.cpp95
-rw-r--r--src/modules/reguser/dialog.h8
-rw-r--r--src/modules/reguser/edituser.cpp77
-rw-r--r--src/modules/reguser/edituser.h4
4 files changed, 120 insertions, 64 deletions
diff --git a/src/modules/reguser/dialog.cpp b/src/modules/reguser/dialog.cpp
index 79d978a2e..e7696e781 100644
--- a/src/modules/reguser/dialog.cpp
+++ b/src/modules/reguser/dialog.cpp
@@ -158,33 +158,38 @@ void KviRegisteredUsersDialogItemDelegate::paint( QPainter * p, const QStyleOpti
if(item->type()==KviRegisteredUsersDialogItemBase::Group)
{
//groups
- QItemDelegate::paint(p, option, index);
+ QStyledItemDelegate::paint(p, option, index);
} else {
- if (option.state & QStyle::State_Selected)
- p->fillRect(option.rect, option.palette.brush( QPalette::Highlight ) );
+ QStyleOptionViewItemV4 opt = option;
+ initStyleOption(&opt, index);
+
+ if (opt.state & QStyle::State_Selected)
+ QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem,&opt, p);
KviRegisteredUsersDialogItem *it=(KviRegisteredUsersDialogItem*)item;
if(index.column()==0)
{
- QPoint pt=option.rect.topLeft();
+ QPoint pt=opt.rect.topLeft();
pt.setX(pt.x()+LVI_BORDER);
pt.setY(pt.y()+LVI_BORDER);
p->drawPixmap(pt, *(g_pIconManager->getBigIcon(KVI_BIGICON_REGUSERS)));
- QRect cliprect=QRect(QPoint(0,0),QSize(option.rect.width()-(LVI_ICON_SIZE+LVI_SPACING+LVI_BORDER),option.rect.height()));
+ QRect cliprect=QRect(QPoint(0,0),QSize(opt.rect.width()-(LVI_ICON_SIZE+LVI_SPACING+LVI_BORDER),opt.rect.height()));
p->save();
- p->translate(option.rect.x()+LVI_ICON_SIZE+LVI_SPACING, option.rect.y());
+ p->translate(opt.rect.x()+LVI_ICON_SIZE+LVI_SPACING, opt.rect.y());
it->m_pText.drawContents(p, cliprect);
p->restore();
} else {
if(it->user())
{
if(!it->user()->getProperty("notify").isEmpty())
- p->drawPixmap(option.rect.topLeft().x()+LVI_BORDER,option.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_NOTIFYONLINE)));
+ p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_NOTIFYONLINE)));
+ else
+ p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_NOTIFYOFFLINE)));
if(it->user()->ignoreEnagled())
- p->drawPixmap(option.rect.topLeft().x()+LVI_BORDER,option.rect.topLeft().y()+2*LVI_BORDER+16,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_IGNORE)));
+ p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+2*LVI_BORDER+16,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_IGNORE)));
}
}
}
@@ -197,7 +202,7 @@ QSize KviRegisteredUsersDialogItemDelegate::sizeHint( const QStyleOptionViewItem
if(item->type()==KviRegisteredUsersDialogItemBase::Group)
{
//groups
- return QItemDelegate::sizeHint(option, index);
+ return QStyledItemDelegate::sizeHint(option, index);
} else {
//users
// KviRegisteredUsersDialogItem *it=(KviRegisteredUsersDialogItem*)item;
@@ -264,6 +269,11 @@ KviRegisteredUsersDialog::KviRegisteredUsersDialog(QWidget * par)
QFrame * f = new QFrame(vbox);
f->setFrameStyle(QFrame::HLine | QFrame::Sunken);
+ m_pSelectAllButton = new QPushButton(__tr2qs_ctx("Select all","register"),vbox);
+ connect(m_pSelectAllButton,SIGNAL(clicked()),this,SLOT(selectAllClicked()));
+ m_pSelectAllButton->setToolTip(__tr2qs_ctx("Select all the entries","register"));
+ m_pSelectAllButton->setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_PLUS)));
+
m_pExportButton = new QPushButton(__tr2qs_ctx("Export To...","register"),vbox);
m_pExportButton->setEnabled(false);
connect(m_pExportButton,SIGNAL(clicked()),this,SLOT(exportClicked()));
@@ -276,7 +286,7 @@ KviRegisteredUsersDialog::KviRegisteredUsersDialog(QWidget * par)
m_pImportButton->setToolTip(__tr2qs_ctx("Import entries from a file exported earlier by the \"export\" function of this dialog.","register"));
m_pImportButton->setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_FOLDER)));
-
+
KviTalHBox * hbox = new KviTalHBox(this);
hbox->setSpacing(4);
g->addWidget(hbox,3,1,1,2);
@@ -349,8 +359,6 @@ void KviRegisteredUsersDialog::itemPressed(QTreeWidgetItem *it,int c)
// notify list toggle
if(i->user()->getProperty("notify").isEmpty())
{
- i->user()->setProperty("notify",""); // kill that
- } else {
// try to find the nicknames to be notified
QString szMask;
@@ -364,15 +372,21 @@ void KviRegisteredUsersDialog::itemPressed(QTreeWidgetItem *it,int c)
}
}
// if the nickname list is still empty , build a dummy nick to notify
- szMask = i->user()->name();
- szMask.replace(" ","");
- szMask.replace("'","");
- szMask.replace("&","");
- szMask.replace(",","");
+ if(szMask.isEmpty())
+ {
+ szMask = i->user()->name();
+ szMask.replace(" ","");
+ szMask.replace("'","");
+ szMask.replace("&","");
+ szMask.replace(",","");
+ }
i->user()->setProperty("notify",szMask);
+ } else {
+ i->user()->setProperty("notify",QString("")); // kill that
}
- m_pListView->update();
+
+ m_pListView->repaint(r);
}
}
}
@@ -426,6 +440,18 @@ void KviRegisteredUsersDialog::editGroup(KviRegisteredUserGroup* group)
}
fillList();
+
+ // select the last edited item
+ for(int c=0;c<m_pListView->topLevelItemCount();c++)
+ {
+ QTreeWidgetItem * pGroup = m_pListView->topLevelItem(c);
+ if(KviQString::equalCI(pGroup->text(0),text))
+ {
+ pGroup->setSelected(true);
+ m_pListView->setCurrentItem(pGroup);
+ break;
+ }
+ }
}
}
@@ -627,16 +653,18 @@ void KviRegisteredUsersDialog::editItem(KviRegisteredUsersDialogItem * i)
fillList();
// select the last edited item
- int count = m_pListView->topLevelItemCount();
- for(int c=0;c<count;c++)
+ for(int c=0;c<m_pListView->topLevelItemCount();c++)
{
- QTreeWidgetItem * i = m_pListView->topLevelItem(c);
- QString szTmp = i->text(0);
- if(KviQString::equalCI(szTmp,szName))
+ QTreeWidgetItem * pGroup = m_pListView->topLevelItem(c);
+ for(int d=0;d<pGroup->childCount();d++)
{
- i->setSelected(true);
- m_pListView->setCurrentItem(i);
- break;
+ KviRegisteredUsersDialogItem * pUser = (KviRegisteredUsersDialogItem*) pGroup->child(d);
+ if(KviQString::equalCI(pUser->user()->name(),szName))
+ {
+ pUser->setSelected(true);
+ m_pListView->setCurrentItem(pUser);
+ break;
+ }
}
}
@@ -662,9 +690,9 @@ void KviRegisteredUsersDialog::selectionChanged()
typedef struct _KviReguserDbFileHeader
{
- unsigned int magic;
- unsigned int version;
- unsigned int nentries;
+ kvi_u32_t magic;
+ kvi_u32_t version;
+ kvi_u32_t nentries;
} KviReguserDbFileHeader;
void KviRegisteredUsersDialog::exportClicked()
@@ -712,11 +740,10 @@ void KviRegisteredUsersDialog::exportClicked()
if(pBase->type()!=KviRegisteredUsersDialogItemBase::User)
continue;
- QString szName = list.at(i)->text(0);
KviRegisteredUser * u = ((KviRegisteredUsersDialogItem *)list.at(i))->user();
if(u)
{
- if(!f.save(szName))goto write_error;
+ if(!f.save(u->name()))goto write_error;
KviPointerHashTable<QString,QString> * pd = u->propertyDict();
if(pd)
{
@@ -783,6 +810,11 @@ succesfull_export:
f.close();
}
+void KviRegisteredUsersDialog::selectAllClicked()
+{
+ m_pListView->selectAll();
+}
+
void KviRegisteredUsersDialog::importClicked()
{
//KviStr buffer;
@@ -823,6 +855,7 @@ void KviRegisteredUsersDialog::importClicked()
QString szName;
if(!f.load(szName))goto read_error;
KviRegisteredUser * u = g_pLocalRegisteredUserDataBase->getUser(szName);
+ if(!u) goto read_error;
unsigned int count = 0;
if(!f.load(count))goto read_error;
for(unsigned int up = 0;up < count;up++)
diff --git a/src/modules/reguser/dialog.h b/src/modules/reguser/dialog.h
index f497e32c9..21c78f422 100644
--- a/src/modules/reguser/dialog.h
+++ b/src/modules/reguser/dialog.h
@@ -35,7 +35,7 @@
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
#include <QMultiHash>
#include <QTextDocument>
@@ -51,11 +51,11 @@ signals:
void rightButtonPressed(QTreeWidgetItem *,QPoint);
};
-class KviRegisteredUsersDialogItemDelegate : public QItemDelegate
+class KviRegisteredUsersDialogItemDelegate : public QStyledItemDelegate
{
public:
KviRegisteredUsersDialogItemDelegate(KviRegisteredUsersListView * pWidget=0)
- : QItemDelegate(pWidget) {};
+ : QStyledItemDelegate(pWidget) {};
~KviRegisteredUsersDialogItemDelegate(){};
QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const;
void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
@@ -131,6 +131,7 @@ public:
QPushButton * m_pImportButton;
QPushButton * m_pExportButton;
QPushButton * m_pAddGroupButton;
+ QPushButton * m_pSelectAllButton;
QMultiHash<int, KviRegisteredUserGroup*> m_TmpDict;
protected:
void fillList();
@@ -148,6 +149,7 @@ protected slots:
void exportClicked();
void addWizardClicked();
void addGroupClicked();
+ void selectAllClicked();
void itemPressed(QTreeWidgetItem *it,int c);
void itemDoubleClicked(QTreeWidgetItem *it, int);
void rightButtonPressed ( QTreeWidgetItem *, QPoint);
diff --git a/src/modules/reguser/edituser.cpp b/src/modules/reguser/edituser.cpp
index 442c80748..76b904374 100644
--- a/src/modules/reguser/edituser.cpp
+++ b/src/modules/reguser/edituser.cpp
@@ -84,7 +84,8 @@ KviReguserPropertiesDialog::KviReguserPropertiesDialog(QWidget * p,KviPointerHas
//g->addMultiCellWidget(m_pTable,0,1,0,1);
g->addWidget(m_pTable,0,0);
m_pTable->setColumnCount(2);
- m_pTable->setSelectionMode(QTableWidget::NoSelection);
+ m_pTable->setSelectionMode(QAbstractItemView::SingleSelection);
+ m_pTable->setSelectionBehavior(QAbstractItemView::SelectRows);
QStringList header;
header.append(__tr2qs_ctx("Property","register"));
@@ -142,10 +143,10 @@ void KviReguserPropertiesDialog::fillData()
while(it.current())
{
QTableWidgetItem * m_pTableItem1 = new QTableWidgetItem(it.currentKey(),QTableWidgetItem::Type);
- m_pTableItem1->setFlags(Qt::ItemIsEditable);
+ m_pTableItem1->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
QTableWidgetItem * m_pTableItem2 = new QTableWidgetItem(*(it.current()),QTableWidgetItem::Type);
- m_pTableItem2->setFlags(Qt::ItemIsEditable);
+ m_pTableItem2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
m_pTable->setItem(row,0,m_pTableItem1);
m_pTable->setItem(row,1,m_pTableItem2);
@@ -178,10 +179,10 @@ void KviReguserPropertiesDialog::addClicked()
m_pTable->setRowCount(m_pTable->rowCount() + 1);
QTableWidgetItem * m_pTableItem1 = new QTableWidgetItem("",QTableWidgetItem::Type);
- m_pTableItem1->setFlags(Qt::ItemIsEditable);
+ m_pTableItem1->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
QTableWidgetItem * m_pTableItem2 = new QTableWidgetItem("",QTableWidgetItem::Type);
- m_pTableItem2->setFlags(Qt::ItemIsEditable);
+ m_pTableItem2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
m_pTable->setItem(m_pTable->rowCount() - 1,0,m_pTableItem1);
m_pTable->setItem(m_pTable->rowCount() - 1,1,m_pTableItem2);
@@ -195,24 +196,7 @@ void KviReguserPropertiesDialog::delClicked()
if((i > -1) && (i < m_pTable->rowCount()))
{
// remove row i
- m_pTable->takeItem(i,0);
- m_pTable->takeItem(i,1);
-
- for(;i < (m_pTable->rowCount() - 1);i++)
- {
- // Get first row's data
- QString cellText1 = m_pTable->item(i,0)->text();
- QString cellText2 = m_pTable->item(i,1)->text();
-
- // Copy second row's data into the first one
- m_pTable->item(i,0)->setText(m_pTable->item(i+1,0)->text());
- m_pTable->item(i,1)->setText(m_pTable->item(i+1,1)->text());
-
- // Set first row's data into the second one
- m_pTable->item(i+1,0)->setText(cellText1);
- m_pTable->item(i+1,1)->setText(cellText2);
- }
- m_pTable->setRowCount(m_pTable->rowCount() - 1);
+ m_pTable->removeRow(i);
if(m_pTable->rowCount() == 0)m_pDelButton->setEnabled(false);
}
}
@@ -394,10 +378,9 @@ KviRegisteredUserEntryDialog::KviRegisteredUserEntryDialog(QWidget *p,KviRegiste
m_pNotifyCheck = new QCheckBox(__tr2qs_ctx("Notify when user is online","register"),p2);
g->addWidget(m_pNotifyCheck,0,0,1,3);
- l = new QLabel(__tr2qs_ctx("Notify nicknames:","register"),p2);
- l->setEnabled(m_pNotifyCheck->isChecked());
- g->addWidget(l,1,0);
- connect(m_pNotifyCheck,SIGNAL(toggled(bool)),l,SLOT(setEnabled(bool)));
+ m_pNotifyLabel = new QLabel(__tr2qs_ctx("Notify nicknames:","register"),p2);
+ m_pNotifyLabel->setEnabled(m_pNotifyCheck->isChecked());
+ g->addWidget(m_pNotifyLabel,1,0);
m_pNotifyCheck->setToolTip(__tr2qs_ctx("<center>You can enter a space separated list of nicknames.</center>","register"));
@@ -405,7 +388,7 @@ KviRegisteredUserEntryDialog::KviRegisteredUserEntryDialog(QWidget *p,KviRegiste
m_pNotifyNick->setEnabled(false);
g->addWidget(m_pNotifyNick,1,1,1,2);
- connect(m_pNotifyCheck,SIGNAL(toggled(bool)),m_pNotifyNick,SLOT(setEnabled(bool)));
+ connect(m_pNotifyCheck,SIGNAL(toggled(bool)),this,SLOT(notifyCheckClicked(bool)));
f = new QFrame(p2);
@@ -553,6 +536,37 @@ KviRegisteredUserEntryDialog::~KviRegisteredUserEntryDialog()
delete m_pCustomColor;
}
+void KviRegisteredUserEntryDialog::notifyCheckClicked(bool bChecked)
+{
+ m_pNotifyNick->setEnabled(bChecked);
+ m_pNotifyLabel->setEnabled(bChecked);
+ if(bChecked and m_pNotifyNick->text().isEmpty())
+ {
+ QString szMask;
+
+ for(KviIrcMask * m = m_pUser->maskList()->first();m;m = m_pUser->maskList()->next())
+ {
+ QString tmp = m->nick();
+ if((tmp.indexOf('*') == -1) && (tmp.indexOf('?') == -1) && (!tmp.isEmpty()))
+ {
+ if(!szMask.isEmpty())szMask.append(' ');
+ szMask.append(tmp);
+ }
+ }
+ // if the nickname list is still empty , build a dummy nick to notify
+ if(szMask.isEmpty())
+ {
+ szMask = m_pUser->name();
+ szMask.replace(" ","");
+ szMask.replace("'","");
+ szMask.replace("&","");
+ szMask.replace(",","");
+ }
+
+ m_pNotifyNick->setText(szMask);
+ }
+}
+
void KviRegisteredUserEntryDialog::maskCurrentChanged()
{
bool bHaveSelected = !m_pMaskListBox->selectedItems().empty();
@@ -627,11 +641,16 @@ void KviRegisteredUserEntryDialog::okClicked()
{
QString szNicks = m_pNotifyNick->text();
- if(!szNicks.isEmpty())
+ if(szNicks.isEmpty())
{
+ u->setProperty("notify",QString(""));
+ } else {
u->setProperty("notify",szNicks);
}
+ } else {
+ u->setProperty("notify",QString(""));
}
+
m_pPropertyDict->remove("notify");
m_pPropertyDict->remove("avatar");
diff --git a/src/modules/reguser/edituser.h b/src/modules/reguser/edituser.h
index 1f4eb7155..f6a3835b3 100644
--- a/src/modules/reguser/edituser.h
+++ b/src/modules/reguser/edituser.h
@@ -106,7 +106,8 @@ protected:
QCheckBox * m_pNotifyCheck;
QLineEdit * m_pNotifyNick;
-
+ QLabel * m_pNotifyLabel;
+
KviPixmap * m_pAvatar;
KviPixmapSelector * m_pAvatarSelector;
@@ -133,6 +134,7 @@ protected slots:
void editMaskClicked();
void editAllPropertiesClicked();
void maskCurrentChanged();
+ void notifyCheckClicked(bool bChecked);
};
#endif //_EDITUSER_H_