Browse Source

- Rewrote part of Arnaud's code for column hiding to debug and optimize it

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
a91d2028d8
  1. 53
      src/FinishedTorrents.cpp
  2. 53
      src/downloadingTorrents.cpp

53
src/FinishedTorrents.cpp

@ -403,42 +403,31 @@ void FinishedTorrents::displayFinishedHoSMenu(const QPoint& pos){
// toggle hide/show a column // toggle hide/show a column
void FinishedTorrents::hideOrShowColumn(int index) { void FinishedTorrents::hideOrShowColumn(int index) {
short nbColumns = 0; unsigned int nbVisibleColumns = 0;
unsigned int nbCols = finishedListModel->columnCount();
// Count visible columns
for(unsigned int i=0; i<nbCols; ++i) {
if(!finishedList->isColumnHidden(i))
++nbVisibleColumns;
}
if(!finishedList->isColumnHidden(index)) { if(!finishedList->isColumnHidden(index)) {
unsigned short i=0, nbColDisplayed = 0; // User wants to hide the column
while(i<finishedListModel->columnCount()-1 && nbColDisplayed<=1) { // Is there at least one other visible column?
if(!finishedList->isColumnHidden(i)) if(nbVisibleColumns <= 1) return;
nbColDisplayed++; // User can hide the column, do it.
i++; finishedList->setColumnHidden(index, true);
} getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png")));
// can't hide a lonely column --nbVisibleColumns;
if(nbColDisplayed>1) {
//resize all others non-hidden columns
for(int i=0; i<finishedListModel->columnCount()-1; i++) {
if(finishedList->isColumnHidden(i) == false)
nbColumns++;
}
for(int i=0; i<finishedListModel->columnCount()-1; i++) {
if(i != index) {
finishedList->setColumnWidth(i, (int)ceil(finishedList->columnWidth(i)+(finishedList->columnWidth(index)/(nbColumns-1))));
}
}
finishedList->setColumnHidden(index, true);
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png")));
}
} else { } else {
//short buf_width = finishedList->columnWidth(index); // User want to display the column
finishedList->setColumnHidden(index, false); finishedList->setColumnHidden(index, false);
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png")));
//resize all others non-hidden columns ++nbVisibleColumns;
for(int i=0; i<finishedListModel->columnCount()-1; i++) { }
if(finishedList->isColumnHidden(i) == false) //resize all others non-hidden columns
nbColumns++; for(unsigned int i=0; i<nbCols; ++i) {
} if(!finishedList->isColumnHidden(i)) {
for(int i=0; i<finishedListModel->columnCount()-1; i++) { finishedList->setColumnWidth(i, (int)ceil(finishedList->columnWidth(i)+(finishedList->columnWidth(index)/nbVisibleColumns)));
if(i != index) {
finishedList->setColumnWidth(i, (int)ceil(finishedList->columnWidth(i)-(finishedList->columnWidth(index)/(nbColumns-1))));
}
} }
} }
} }

53
src/downloadingTorrents.cpp

@ -321,42 +321,31 @@ void DownloadingTorrents::displayDLHoSMenu(const QPoint& pos){
// toggle hide/show a column // toggle hide/show a column
void DownloadingTorrents::hideOrShowColumn(int index) { void DownloadingTorrents::hideOrShowColumn(int index) {
short nbColumns = 0; unsigned int nbVisibleColumns = 0;
unsigned int nbCols = DLListModel->columnCount();
// Count visible columns
for(unsigned int i=0; i<nbCols; ++i) {
if(!downloadList->isColumnHidden(i))
++nbVisibleColumns;
}
if(!downloadList->isColumnHidden(index)) { if(!downloadList->isColumnHidden(index)) {
unsigned short i=0, nbColDisplayed = 0; // User wants to hide the column
while(i<DLListModel->columnCount()-1 && nbColDisplayed<=1) { // Is there at least one other visible column?
if(!downloadList->isColumnHidden(i)) if(nbVisibleColumns <= 1) return;
nbColDisplayed++; // User can hide the column, do it.
i++; downloadList->setColumnHidden(index, true);
} getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png")));
// can't hide a lonely column --nbVisibleColumns;
if(nbColDisplayed>1) {
//resize all others non-hidden columns
for(int i=0; i<DLListModel->columnCount()-1; i++) {
if(downloadList->isColumnHidden(i) == false)
nbColumns++;
}
for(int i=0; i<DLListModel->columnCount()-1; i++) {
if(i != index) {
downloadList->setColumnWidth(i, (int)ceil(downloadList->columnWidth(i)+(downloadList->columnWidth(index)/(nbColumns-1))));
}
}
downloadList->setColumnHidden(index, true);
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png")));
}
} else { } else {
//short buf_width = finishedList->columnWidth(index); // User want to display the column
downloadList->setColumnHidden(index, false); downloadList->setColumnHidden(index, false);
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png")));
//resize all others non-hidden columns ++nbVisibleColumns;
for(int i=0; i<DLListModel->columnCount()-1; i++) { }
if(downloadList->isColumnHidden(i) == false) //resize all others non-hidden columns
nbColumns++; for(unsigned int i=0; i<nbCols; ++i) {
} if(!downloadList->isColumnHidden(i)) {
for(int i=0; i<DLListModel->columnCount()-1; i++) { downloadList->setColumnWidth(i, (int)ceil(downloadList->columnWidth(i)+(downloadList->columnWidth(index)/nbVisibleColumns)));
if(i != index) {
downloadList->setColumnWidth(i, (int)ceil(downloadList->columnWidth(i)-(downloadList->columnWidth(index)/(nbColumns-1))));
}
} }
} }
} }

Loading…
Cancel
Save