diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index 3a7bb75c9..8c2374856 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -403,42 +403,31 @@ void FinishedTorrents::displayFinishedHoSMenu(const QPoint& pos){ // toggle hide/show a column 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; iisColumnHidden(i)) + ++nbVisibleColumns; + } if(!finishedList->isColumnHidden(index)) { - unsigned short i=0, nbColDisplayed = 0; - while(icolumnCount()-1 && nbColDisplayed<=1) { - if(!finishedList->isColumnHidden(i)) - nbColDisplayed++; - i++; - } - // can't hide a lonely column - if(nbColDisplayed>1) { - //resize all others non-hidden columns - for(int i=0; icolumnCount()-1; i++) { - if(finishedList->isColumnHidden(i) == false) - nbColumns++; - } - for(int i=0; icolumnCount()-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"))); - } + // User wants to hide the column + // Is there at least one other visible column? + if(nbVisibleColumns <= 1) return; + // User can hide the column, do it. + finishedList->setColumnHidden(index, true); + getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); + --nbVisibleColumns; } else { - //short buf_width = finishedList->columnWidth(index); + // User want to display the column finishedList->setColumnHidden(index, false); getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); - //resize all others non-hidden columns - for(int i=0; icolumnCount()-1; i++) { - if(finishedList->isColumnHidden(i) == false) - nbColumns++; - } - for(int i=0; icolumnCount()-1; i++) { - if(i != index) { - finishedList->setColumnWidth(i, (int)ceil(finishedList->columnWidth(i)-(finishedList->columnWidth(index)/(nbColumns-1)))); - } + ++nbVisibleColumns; + } + //resize all others non-hidden columns + for(unsigned int i=0; iisColumnHidden(i)) { + finishedList->setColumnWidth(i, (int)ceil(finishedList->columnWidth(i)+(finishedList->columnWidth(index)/nbVisibleColumns))); } } } diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index 1aecee420..178835a49 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -321,42 +321,31 @@ void DownloadingTorrents::displayDLHoSMenu(const QPoint& pos){ // toggle hide/show a column 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; iisColumnHidden(i)) + ++nbVisibleColumns; + } if(!downloadList->isColumnHidden(index)) { - unsigned short i=0, nbColDisplayed = 0; - while(icolumnCount()-1 && nbColDisplayed<=1) { - if(!downloadList->isColumnHidden(i)) - nbColDisplayed++; - i++; - } - // can't hide a lonely column - if(nbColDisplayed>1) { - //resize all others non-hidden columns - for(int i=0; icolumnCount()-1; i++) { - if(downloadList->isColumnHidden(i) == false) - nbColumns++; - } - for(int i=0; icolumnCount()-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"))); - } + // User wants to hide the column + // Is there at least one other visible column? + if(nbVisibleColumns <= 1) return; + // User can hide the column, do it. + downloadList->setColumnHidden(index, true); + getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); + --nbVisibleColumns; } else { - //short buf_width = finishedList->columnWidth(index); + // User want to display the column downloadList->setColumnHidden(index, false); getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); - //resize all others non-hidden columns - for(int i=0; icolumnCount()-1; i++) { - if(downloadList->isColumnHidden(i) == false) - nbColumns++; - } - for(int i=0; icolumnCount()-1; i++) { - if(i != index) { - downloadList->setColumnWidth(i, (int)ceil(downloadList->columnWidth(i)-(downloadList->columnWidth(index)/(nbColumns-1)))); - } + ++nbVisibleColumns; + } + //resize all others non-hidden columns + for(unsigned int i=0; iisColumnHidden(i)) { + downloadList->setColumnWidth(i, (int)ceil(downloadList->columnWidth(i)+(downloadList->columnWidth(index)/nbVisibleColumns))); } } }