29 #include <KPushButton>
33 #include <KGlobalSettings>
35 #include <QtGui/QLabel>
36 #include <QtGui/QLayout>
37 #include <QtGui/QSpinBox>
38 #include <QtGui/QSortFilterProxyModel>
39 #include <QtGui/QHeaderView>
40 #include <QtGui/QTreeView>
41 #include <QtGui/QClipboard>
42 #include <QtGui/QApplication>
43 #include <QtGui/QFocusEvent>
52 :
QWidget( parent ), mTool( tool )
54 QVBoxLayout *baseLayout =
new QVBoxLayout(
this );
55 baseLayout->setMargin( 0 );
58 QHBoxLayout *updateLayout =
new QHBoxLayout();
60 updateLayout->addStretch();
61 QLabel *label =
new QLabel( i18nc(
"@label:spinbox minimum length for consecutive chars to be seen as a string",
62 "Minimum length:"),
this );
63 updateLayout->addWidget( label );
65 mMinLengthSpinBox =
new QSpinBox(
this );
66 mMinLengthSpinBox->setValue( mTool->
minLength() );
68 connect( mMinLengthSpinBox, SIGNAL(valueChanged(
int)), mTool, SLOT(setMinLength(
int)) );
69 label->setBuddy( mMinLengthSpinBox );
70 updateLayout->addWidget( mMinLengthSpinBox );
72 const KGuiItem updateGuiItem =
73 KGuiItem( i18nc(
"@action:button extract the strings from the byte array",
"&Extract"),
74 QLatin1String(
"document-export"),
75 i18nc(
"@info:tooltip",
76 "Finds the strings contained in the selected range and lists them in the view below."),
77 i18nc(
"@info:whatsthis",
78 "If you press the <interface>Extract</interface> button, "
79 "the selected range is searched for all strings which have the set minimum length. "
80 "This strings found will be listed in the view below.") );
81 mUpdateButton =
new KPushButton( updateGuiItem,
this );
83 connect( mUpdateButton, SIGNAL(clicked(
bool)), mTool, SLOT(extractStrings()) );
84 updateLayout->addWidget( mUpdateButton );
86 baseLayout->addLayout( updateLayout );
89 QHBoxLayout *filterLayout =
new QHBoxLayout();
91 label =
new QLabel( i18nc(
"@label:lineedit filter term for displayed strings",
"Filter:"),
this );
92 filterLayout->addWidget( label );
95 mFilterEdit->setClearButtonShown(
true );
96 mFilterEdit->setClickMessage( i18n(
"Enter a term to limit the list.") );
97 label->setBuddy( mFilterEdit );
98 filterLayout->addWidget( mFilterEdit, 10 );
100 baseLayout->addLayout( filterLayout );
103 mContainedStringTableModel =
105 connect( mTool, SIGNAL(offsetCodingChanged(
int)),
106 mContainedStringTableModel, SLOT(setOffsetCoding(
int)) );
108 mSortFilterProxyModel =
new QSortFilterProxyModel(
this );
109 mSortFilterProxyModel->setDynamicSortFilter(
true );
110 mSortFilterProxyModel->setSourceModel( mContainedStringTableModel );
112 mSortFilterProxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
113 connect( mFilterEdit, SIGNAL(textChanged(QString)),
114 mSortFilterProxyModel, SLOT(setFilterFixedString(QString)) );
116 mContainedStringTableView =
new QTreeView(
this );
117 connect( KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
118 SLOT(setFixedFontByGlobalSettings()) );
119 setFixedFontByGlobalSettings();
120 mContainedStringTableView->setObjectName( QLatin1String(
"ContainedStringTable" ) );
121 mContainedStringTableView->setRootIsDecorated(
false );
122 mContainedStringTableView->setItemsExpandable(
false );
123 mContainedStringTableView->setUniformRowHeights(
true );
124 mContainedStringTableView->setAllColumnsShowFocus(
true );
125 mContainedStringTableView->setSelectionMode( QAbstractItemView::ExtendedSelection );
126 mContainedStringTableView->setSortingEnabled(
true );
127 mContainedStringTableView->installEventFilter(
this );
128 QHeaderView* header = mContainedStringTableView->header();
129 header->setFont( font() );
130 header->setResizeMode( QHeaderView::Interactive );
131 mContainedStringTableView->setModel( mSortFilterProxyModel );
133 connect( mContainedStringTableView, SIGNAL(doubleClicked(QModelIndex)),
134 SLOT(onStringDoubleClicked(QModelIndex)) );
135 connect( mContainedStringTableView->selectionModel(),
136 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
137 SLOT(onStringSelectionChanged()) );
139 baseLayout->addWidget( mContainedStringTableView, 10 );
142 QHBoxLayout *actionsLayout =
new QHBoxLayout();
144 const KGuiItem copyGuiItem =
145 KGuiItem( i18n(
"C&opy"),
146 QLatin1String(
"edit-copy"),
147 i18nc(
"@info:tooltip",
148 "Copies the selected strings to the clipboard."),
149 i18nc(
"@info:whatsthis",
150 "If you press the <interface>Copy</interface> button, all strings you selected "
151 "in the list are copied to the clipboard.") );
152 mCopyButton =
new KPushButton( copyGuiItem,
this );
153 connect( mCopyButton, SIGNAL(clicked(
bool)), SLOT(onCopyButtonClicked()) );
154 actionsLayout->addWidget( mCopyButton );
156 actionsLayout->addStretch();
158 const KGuiItem gotoGuiItem =
159 KGuiItem( i18n(
"&Show"),
160 QLatin1String(
"go-jump"),
161 i18nc(
"@info:tooltip",
162 "Shows the selected string in the view."),
163 i18nc(
"@info:whatsthis",
164 "If you press the <interface>Go to</interface> button, the string which was last "
165 "selected is marked and shown in the view.") );
166 mGotoButton =
new KPushButton( gotoGuiItem,
this );
167 connect( mGotoButton, SIGNAL(clicked(
bool)), SLOT(onGotoButtonClicked()) );
168 actionsLayout->addWidget( mGotoButton );
170 baseLayout->addLayout( actionsLayout );
172 connect( mTool, SIGNAL(uptodateChanged(
bool)), SLOT(onStringsUptodateChanged(
bool)) );
173 connect( mTool, SIGNAL(isApplyableChanged(
bool)), SLOT(onApplyableChanged(
bool)));
174 connect( mTool, SIGNAL(canHighlightStringChanged(
bool)), SLOT(onCanHighlightStringChanged(
bool)) );
176 onStringSelectionChanged();
181 if(
object == mContainedStringTableView )
183 if( event->type() == QEvent::FocusOut )
185 QFocusEvent* focusEvent =
static_cast<QFocusEvent*
>( event );
186 const Qt::FocusReason focusReason = focusEvent->reason();
187 if( focusReason != Qt::ActiveWindowFocusReason
188 && focusReason != Qt::PopupFocusReason )
193 return QWidget::eventFilter(
object, event );
196 void StringsExtractView::setFixedFontByGlobalSettings()
198 mContainedStringTableView->setFont( KGlobalSettings::fixedFont() );
201 void StringsExtractView::onStringsUptodateChanged(
bool stringsUptodate )
203 if( stringsUptodate )
204 mContainedStringTableModel->
update();
207 mUpdateButton->setEnabled( !stringsUptodate && isApplyable );
210 void StringsExtractView::onApplyableChanged(
bool isApplyable )
212 mUpdateButton->setEnabled( !mTool->
isUptodate() && isApplyable );
215 void StringsExtractView::onCanHighlightStringChanged(
bool canHighlightString )
217 const bool stringSelected = mContainedStringTableView->selectionModel()->currentIndex().isValid();
218 mGotoButton->setEnabled( canHighlightString && stringSelected );
222 void StringsExtractView::onGotoButtonClicked()
224 const QModelIndex index = mContainedStringTableView->selectionModel()->currentIndex();
225 if( index.isValid() )
228 mContainedStringTableView->setFocus();
229 onStringDoubleClicked( index );
233 void StringsExtractView::onCopyButtonClicked()
235 const QModelIndexList selectedRows = mContainedStringTableView->selectionModel()->selectedRows();
239 foreach(
const QModelIndex &index, selectedRows )
241 const int i = mSortFilterProxyModel->mapToSource(index).row();
242 strings += containedStringList->at( i ).string();
243 strings += QLatin1Char(
'\n');
245 QApplication::clipboard()->setText( strings );
248 void StringsExtractView::onStringSelectionChanged()
250 const QItemSelectionModel *selectionModel = mContainedStringTableView->selectionModel();
254 const bool hasSelection = !selectionModel->selectedIndexes().isEmpty();
255 mCopyButton->setEnabled( hasSelection );
257 const bool stringSelected = selectionModel->isSelected( selectionModel->currentIndex() );
259 mGotoButton->setEnabled( canHighlightString && stringSelected );
262 void StringsExtractView::onStringDoubleClicked(
const QModelIndex &index )
265 mTool->
markString( mSortFilterProxyModel->mapToSource(index).row() );
static const int MinimumStringLength