PropertiesPanel.cpp

Go to the documentation of this file.
00001 #include "PropertiesPanel.h"
00002 
00003 PropertiesPanel::PropertiesPanel( const Preferences& prefs, QWidget* parent ) 
00004     : QVBox( parent ), prefs( prefs ), editedVocab( NULL), editedFolder( NULL ) {
00005     setSpacing( 2 );
00006     init();
00007 }
00008 
00009 void PropertiesPanel::setVocabulary( Vocabulary* vocab ) {
00010     removeListeners();
00011 
00012     editedVocab = vocab;
00013 
00014     descriptionMultiLineEdit->setText( editedVocab->getDescription() );
00015     authorLineEdit->setText( editedVocab->getAuthor() );
00016     creationDateValueLabel->setText( editedVocab->getCreationDate().toString() );
00017     modificationDateValueLabel->setText( editedVocab->getModificationDate().toString() );
00018 
00019     updateCounters();
00020 
00021     addListeners();
00022 }
00023 
00024 void PropertiesPanel::setFolder( Folder* folder ) {
00025     removeListeners();
00026 
00027     editedFolder = folder;
00028 
00029     descriptionMultiLineEdit->setText( editedFolder->getDescription() );
00030     authorLineEdit->setText( editedFolder->getAuthor() );
00031     creationDateValueLabel->setText( editedFolder->getCreationDate().toString() );
00032     modificationDateValueLabel->setText( editedFolder->getModificationDate().toString() );
00033 
00034     updateCounters();
00035 
00036     addListeners();
00037 }
00038 
00039 void PropertiesPanel::updateCounters() {
00040     if( getType() == QString( "Vocabulary" ) ) {
00041         uint termCount = 0;
00042         uint checkedTermCount = 0;
00043         uint selectedTermCount = 0;
00044         if( editedVocab ) {
00045             bool isReachableFromRoot = editedVocab->isMarkedForStudy() && editedVocab->getParent()->isReachableFromRoot();
00046             if( prefs.isLanguageFilterEnabled() )
00047                 editedVocab->getItemsCount( &termCount, &checkedTermCount, &selectedTermCount, isReachableFromRoot, 
00048                     prefs.getFirstLanguage(), prefs.getTestLanguage() );
00049             else
00050                 editedVocab->getItemsCount( &termCount, &checkedTermCount, &selectedTermCount, isReachableFromRoot );
00051         }
00052 
00053         contentListView->clear();
00054         QListViewItem* termCountItem = new QListViewItem( contentListView, tr( "Words" ), 
00055             QString::number( selectedTermCount ), QString::number( checkedTermCount ), QString::number( termCount ) );
00056         contentListView->insertItem( termCountItem );
00057     }
00058     else if( getType() == QString( "Folder" ) ) {
00059         uint termCount = 0;
00060         uint vocabCount = 0;
00061         uint folderCount = 0;
00062         uint checkedTermCount = 0;
00063         uint checkedVocabCount = 0;
00064         uint checkedFolderCount = 0;
00065         uint selectedTermCount = 0;
00066         uint selectedVocabCount = 0;
00067         uint selectedFolderCount = 0;
00068 
00069         if( editedFolder ) {
00070             if( prefs.isLanguageFilterEnabled() )
00071                 editedFolder->getItemsCount( &termCount, &vocabCount, &folderCount, 
00072                     &checkedTermCount, &checkedVocabCount, &checkedFolderCount, 
00073                         &selectedTermCount, &selectedVocabCount, &selectedFolderCount, 
00074                             editedFolder->isReachableFromRoot(),
00075                                 prefs.getFirstLanguage(), prefs.getTestLanguage() );
00076             else
00077                 editedFolder->getItemsCount( &termCount, &vocabCount, &folderCount, 
00078                     &checkedTermCount, &checkedVocabCount, &checkedFolderCount,
00079                         &selectedTermCount, &selectedVocabCount, &selectedFolderCount, editedFolder->isReachableFromRoot() );
00080         }
00081 
00082         contentListView->clear();
00083         QListViewItem* termCountItem = new QListViewItem( contentListView, tr( "Words" ), 
00084             QString::number( selectedTermCount ), QString::number( checkedTermCount ), QString::number( termCount ) );
00085         QListViewItem* vocabCountItem = new QListViewItem( contentListView, tr( "Glossaries" ), 
00086             QString::number( selectedVocabCount ), QString::number( checkedVocabCount ), QString::number( vocabCount ) );
00087         QListViewItem* folderCountItem = new QListViewItem( contentListView, tr( "Folders" ), 
00088             QString::number( selectedFolderCount ), QString::number( checkedFolderCount ), QString::number( folderCount ) );
00089         contentListView->insertItem( termCountItem );
00090         contentListView->insertItem( vocabCountItem );
00091         contentListView->insertItem( folderCountItem );
00092     }
00093     contentListView->updateGeometry();
00094     layout()->invalidate();
00095 }
00096 
00097 void PropertiesPanel::init() {
00098     QFont mediumFont( prefs.getMediumFont() );
00099     QFont labelsFont( prefs.getLabelsFont() );
00100     bool isDigraphEnabled( prefs.isDigraphEnabled() );
00101 
00102     descriptionLabel = new QLabel( tr( "Description" ), this, "DescriptionLabel" );
00103     descriptionMultiLineEdit = new DigraphMultiLineEdit( this, "DescriptionMultiLineEdit" );
00104     descriptionMultiLineEdit->setWrapPolicy( QMultiLineEdit::Anywhere );
00105     descriptionMultiLineEdit->setWordWrap( QMultiLineEdit::WidgetWidth );
00106     descriptionMultiLineEdit->setFont( mediumFont );
00107     descriptionMultiLineEdit->setDigraphEnabled( isDigraphEnabled );
00108     setStretchFactor( descriptionMultiLineEdit, 1 );
00109 
00110     contentLabel = new QLabel( tr( "Content" ), this, "ContentLabel" );
00111     contentListView = new ContentListView( this, "ContentListView" );
00112     contentListView->setAllColumnsShowFocus( true );
00113     contentListView->setSelectionMode( QListView::Extended );
00114     /*int colItems = */contentListView->addColumn( tr( "Items" ) );
00115     int colSelected = contentListView->addColumn( tr( "Selected" ) );
00116     int colChecked = contentListView->addColumn( tr( "Checked" ) );
00117     int colTotal = contentListView->addColumn( tr( "Total" ) );
00118     contentListView->setColumnAlignment( colSelected, QListView::AlignRight );
00119     contentListView->setColumnAlignment( colChecked, QListView::AlignRight );
00120     contentListView->setColumnAlignment( colTotal, QListView::AlignRight );
00121     contentListView->setStretchColumn( 0 );
00122 
00123     simplePropsPanel = new QHBox( this, "SimplePropsPanel" );
00124     simplePropsPanel->setSpacing( 10 );
00125 
00126     simplePropsLabelsPanel = new QVBox( simplePropsPanel, "SimplePropsLabelsPanel" );
00127     simplePropsFieldsPanel = new QVBox( simplePropsPanel, "SimplePropsFieldsPanel" );
00128 
00129     authorLabel = new QLabel( tr( "Author" ), simplePropsLabelsPanel, "AuthorLabel" );
00130     authorLineEdit = new DigraphLineEdit( simplePropsFieldsPanel, "AuthorLineEdit" ); 
00131     authorLineEdit->setFont( mediumFont );
00132     authorLineEdit->setDigraphEnabled( isDigraphEnabled );
00133 
00134     creationDateLabel = new QLabel( tr( "CreationDate" ), simplePropsLabelsPanel, "CreationDateLabel" );
00135     creationDateValueLabel = new QLabel( QString::null, simplePropsFieldsPanel, "CreationDateLineEdit" ); 
00136     creationDateValueLabel->setFont( mediumFont );
00137 
00138     modificationDateLabel = new QLabel( tr( "ModificationDate" ), simplePropsLabelsPanel, "ModificationDateLabel" );
00139     modificationDateValueLabel = new QLabel( QString::null, simplePropsFieldsPanel, "ModificationDateLineEdit" ); 
00140     modificationDateValueLabel->setFont( mediumFont );
00141 }
00142 
00143 PropertiesPanel::~PropertiesPanel() {
00144 }
00145 
00146 void PropertiesPanel::updateAuthor( const QString& author ) {
00147     if( getType() == QString( "Vocabulary" ) ) {
00148         editedVocab->setAuthor( author );
00149         editedVocab->setModificationDate( QDateTime::currentDateTime() );
00150         editedVocab->setDirty( true );
00151     }
00152     else if( getType() == QString( "Folder" ) ) {
00153         editedFolder->setAuthor( author );
00154         editedFolder->setModificationDate( QDateTime::currentDateTime() );
00155         editedFolder->setDirty( true );
00156     }
00157 }
00158 
00159 void PropertiesPanel::updateDescription() {
00160     if( getType() == QString( "Vocabulary" ) ) {
00161         editedVocab->setDescription( descriptionMultiLineEdit->text() );
00162         editedVocab->setModificationDate( QDateTime::currentDateTime() );
00163         editedVocab->setDirty( true );
00164     }
00165     else if( getType() == QString( "Folder" ) ) {
00166         editedFolder->setDescription( descriptionMultiLineEdit->text() );
00167         editedFolder->setModificationDate( QDateTime::currentDateTime() );
00168         editedFolder->setDirty( true );
00169     }
00170 }
00171 
00172 QString PropertiesPanel::getType() const {
00173     return( editedVocab ? QString( "Vocabulary" ) : QString( "Folder" ) );
00174 }
00175 
00176 void PropertiesPanel::updateFonts() {
00177     QFont mediumFont( prefs.getMediumFont() );
00178     QFont labelsFont( prefs.getLabelsFont() );
00179 
00180     descriptionLabel->setFont( labelsFont );
00181     descriptionMultiLineEdit->setFont( mediumFont );
00182     contentLabel->setFont( labelsFont );
00183     contentListView->header()->setFont( labelsFont );
00184     contentListView->setFont( mediumFont ); 
00185     authorLabel->setFont( labelsFont );
00186     authorLineEdit->setFont( mediumFont );
00187     creationDateLabel->setFont( labelsFont );
00188     creationDateValueLabel->setFont( mediumFont );
00189     modificationDateLabel->setFont( labelsFont );
00190     modificationDateValueLabel->setFont( mediumFont );
00191 }
00192 
00193 void PropertiesPanel::setDigraphEnabled( bool isEnabled ) {
00194     descriptionMultiLineEdit->setDigraphEnabled( isEnabled );
00195     authorLineEdit->setDigraphEnabled( isEnabled );
00196 }
00197 
00198 void PropertiesPanel::retranslateUi() {
00199     descriptionLabel->setText( tr( "Description" ) );
00200     contentLabel->setText( tr( "Content" ) );
00201     contentListView->setColumnText( 0, tr( "Items" ) ); 
00202     contentListView->setColumnText( 1, tr( "Selected" ) ); 
00203     contentListView->setColumnText( 2, tr( "Checked" ) ); 
00204     contentListView->setColumnText( 3, tr( "Total" ) ); 
00205     authorLabel->setText( tr( "Author" ) );
00206     creationDateLabel->setText( tr( "CreationDate" ) );
00207     modificationDateLabel->setText( tr( "ModificationDate" ) );
00208 }
00209 
00210 void PropertiesPanel::addListeners() {
00211     connect( authorLineEdit, SIGNAL( textChanged( const QString& ) ),
00212         this, SLOT( updateAuthor( const QString& ) ) );
00213     connect( descriptionMultiLineEdit, SIGNAL( textChanged() ),
00214         this, SLOT( updateDescription() ) );
00215 }
00216 
00217 void PropertiesPanel::removeListeners() {
00218     disconnect( authorLineEdit, SIGNAL( textChanged( const QString& ) ),
00219         this, SLOT( updateAuthor( const QString& ) ) );
00220     disconnect( descriptionMultiLineEdit, SIGNAL( textChanged() ),
00221         this, SLOT( updateDescription() ) );
00222 }
00223 

Generated on Sun Mar 1 17:30:47 2009 for toMOTko by  doxygen 1.5.6