diff --git a/history.cc b/history.cc index b43c02a3..db8d7b12 100644 --- a/history.cc +++ b/history.cc @@ -7,13 +7,13 @@ #include #include -History::History( unsigned size ): maxSize( size ), -addingEnabled( true ) +History::History( unsigned size, unsigned maxItemLength_ ): maxSize( size ), + maxItemLength( maxItemLength_ ), addingEnabled( true ) { } -History::History( Load, unsigned size ): maxSize( size ), -addingEnabled( true ) +History::History( Load, unsigned size, unsigned maxItemLength_ ): maxSize( size ), + maxItemLength( maxItemLength_ ), addingEnabled( true ) { QFile file( Config::getHistoryFileName() ); @@ -64,7 +64,7 @@ void History::addItem( Item const & item ) if( !enabled() ) return; - if ( item.word.size() > MAX_HISTORY_ITEM_LENGTH || item.word.isEmpty() ) + if ( (unsigned)item.word.size() > getMaxItemLength() || item.word.isEmpty() ) { // The search looks bogus. Don't save it. return; diff --git a/history.hh b/history.hh index 62c0f1e4..e3acda7c 100644 --- a/history.hh +++ b/history.hh @@ -8,7 +8,7 @@ #include #include -#define MAX_HISTORY_ITEM_LENGTH 60 +#define DEFAULT_MAX_HISTORY_ITEM_LENGTH 256 /// Search history class History: public QObject @@ -43,11 +43,11 @@ public: struct Load {}; /// Constructs an empty history which can hold at most "size" items. - History( unsigned size = 20 ); + History( unsigned size = 20 , unsigned maxItemLength = DEFAULT_MAX_HISTORY_ITEM_LENGTH ); /// Loads history from its file. If load fails, the result would be an empty /// history. The size parameter is same as in other constructor. - History( Load, unsigned size = 20 ); + History( Load, unsigned size = 20, unsigned maxItemLength = DEFAULT_MAX_HISTORY_ITEM_LENGTH ); /// Adds new item. The item is always added at the beginning of the list. /// If there was such an item already somewhere on the list, it gets removed @@ -86,6 +86,9 @@ public: unsigned getMaxSize() { return maxSize; } + unsigned getMaxItemLength() const + { return maxItemLength; } + signals: /// Signals the changes in items in response to addItem() or clear(). @@ -99,6 +102,7 @@ private: QList< Item > items; unsigned maxSize; + unsigned maxItemLength; bool addingEnabled; }; diff --git a/historypanewidget.cc b/historypanewidget.cc index 373508ba..42335e2f 100644 --- a/historypanewidget.cc +++ b/historypanewidget.cc @@ -239,7 +239,7 @@ QVariant HistoryModel::data( QModelIndex const & index, int role ) const return QVariant(); } - if ( role == Qt::DisplayRole ) + if ( role == Qt::DisplayRole || role == Qt::ToolTipRole ) { return m_history->getItem( index.row() ).word; } diff --git a/mainwindow.cc b/mainwindow.cc index fb4f03ef..e435caec 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -66,7 +66,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): trayIconMenu( this ), addTab( this ), cfg( cfg_ ), - history( History::Load(), cfg_.preferences.maxStringsInHistory ), + history( History::Load(), cfg_.preferences.maxStringsInHistory, cfg_.maxHeadwordSize ), dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine ), articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle, cfg.preferences.addonStyle ), @@ -3151,7 +3151,7 @@ void MainWindow::on_importHistory_triggered() if( trimmedStr.isEmpty() ) continue; - if( trimmedStr.size() <= MAX_HISTORY_ITEM_LENGTH ) + if( (unsigned)trimmedStr.size() <= history.getMaxItemLength( ) ) itemList.prepend( trimmedStr ); } while( !fileStream.atEnd() && itemList.size() < (int)history.getMaxSize() );