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
|
/****************************************************************************
qRFCView, A smart IETF RFC viewer based on the Qt4 library.
Copyright (C) 2005 Mitsubishi Electric ITE-TCL, R. Rollet (rollet@tcl.ite.mee.com)
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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*********************************************************************************/
#include <QFileDialog>
#include "cdialogsetdirectory.h"
CDialogSetDirectory::CDialogSetDirectory( QStringList *pDirectoryList, uint8_t iDefaultDirRow, QString &qRFCURL, QWidget *parent)
: QDialog(parent)
{
int i;
QListWidgetItem *newItem;
m_ui.setupUi(this);
connect(m_ui.addButton, SIGNAL(pressed()), this, SLOT(addDirectoryToList()) );
connect(m_ui.remButton, SIGNAL(pressed()), this, SLOT(remDirectoryFromList()) );
connect(m_ui.applyButton, SIGNAL(pressed()), this, SLOT(accept() ) );
connect(m_ui.cancelButton, SIGNAL(pressed()), this, SLOT(reject() ) );
connect(m_ui.defaultButton, SIGNAL(pressed()), this, SLOT(setDefaultDirectory() ) );
m_ui.urlLineEdit->setText(qRFCURL);
if (pDirectoryList!=NULL)
{
for (i = 0; i < pDirectoryList->size(); i++)
{
newItem = new QListWidgetItem( pDirectoryList->at(i) );
if (i==iDefaultDirRow)
{
QFont qFont=newItem->font();
qFont.setBold(true);
newItem->setFont( qFont );
}
m_ui.directoryList->addItem(newItem);
}
}
m_iDefaultDirRow=iDefaultDirRow;
}
CDialogSetDirectory::~CDialogSetDirectory()
{
}
int CDialogSetDirectory::GetDirectoryList(QStringList *pDirectoryList)
{
int i;
pDirectoryList->clear();
for (i=0;i<m_ui.directoryList->count();i++)
{
pDirectoryList->append( m_ui.directoryList->item(i)->text() );
}
return m_iDefaultDirRow;
}
void CDialogSetDirectory::addDirectoryToList()
{
QString qDirectoryName = QFileDialog::getExistingDirectory( this, "Choose a directory");
if (!qDirectoryName.isEmpty())
{
QListWidgetItem *newItem = new QListWidgetItem(qDirectoryName);
m_ui.directoryList->addItem(newItem);
}
}
void CDialogSetDirectory::remDirectoryFromList()
{
QListWidgetItem *pCurrentItem=m_ui.directoryList->currentItem();
if (pCurrentItem!=NULL)
{
// Update the default index
if (m_iDefaultDirRow>m_ui.directoryList->currentRow())
m_iDefaultDirRow--;
m_ui.directoryList->takeItem(m_ui.directoryList->currentRow() );
delete pCurrentItem;
}
}
void CDialogSetDirectory::setDefaultDirectory()
{
QListWidgetItem *pCurrentItem=m_ui.directoryList->currentItem();
QListWidgetItem *pPrevDefaultItem=m_ui.directoryList->item(m_iDefaultDirRow);
if (pCurrentItem!=NULL)
{
QFont qFont=pCurrentItem->font();
pPrevDefaultItem->setFont( qFont );
qFont.setBold(true);
pCurrentItem->setFont( qFont );
m_iDefaultDirRow=m_ui.directoryList->currentRow();
}
}
|