34 #include <KPushButton>
38 #include <KGlobalSettings>
40 #include <QtGui/QLabel>
41 #include <QtGui/QGroupBox>
42 #include <QtGui/QStackedWidget>
43 #include <QtGui/QLayout>
44 #include <QtGui/QClipboard>
45 #include <QtGui/QApplication>
46 #include <QtGui/QAbstractItemView>
56 QVBoxLayout* baseLayout =
new QVBoxLayout(
this );
57 baseLayout->setMargin( 0 );
60 QHBoxLayout* algorithmLayout =
new QHBoxLayout();
61 QLabel* label =
new QLabel( i18nc(
"@label:listbox algorithm to use for the checksum",
"Algorithm:"),
this );
62 mAlgorithmComboBox =
new KComboBox(
this );
63 connect( mAlgorithmComboBox, SIGNAL(activated(
int)),
64 SLOT(onOperationChange(
int)) );
66 label->setBuddy( mAlgorithmComboBox );
67 const QString algorithmWhatsThis =
68 i18nc(
"@info:whatsthis",
"Select the algorithm to use for the checksum.");
69 label->setWhatsThis( algorithmWhatsThis );
70 mAlgorithmComboBox->setWhatsThis( algorithmWhatsThis );
72 algorithmLayout->addWidget( label );
73 algorithmLayout->addWidget( mAlgorithmComboBox, 10 );
74 baseLayout->addLayout( algorithmLayout );
77 QGroupBox* parameterSetBox =
new QGroupBox( i18nc(
"@title:group",
"Parameters"),
this );
78 baseLayout->addWidget( parameterSetBox );
80 QVBoxLayout* parameterSetLayout =
new QVBoxLayout( parameterSetBox );
82 mParameterSetEditStack =
new QStackedWidget( parameterSetBox );
83 parameterSetLayout->addWidget( mParameterSetEditStack );
86 QHBoxLayout* calculateLayout =
new QHBoxLayout();
88 calculateLayout->addStretch();
89 const KGuiItem updateGuiItem =
90 KGuiItem( i18nc(
"@action:button calculate the checksum",
"&Calculate"),
91 QLatin1String(
"run-build"),
92 i18nc(
"@info:tooltip",
93 "Calculate the checksum for the bytes in the selected range."),
94 i18nc(
"@info:whatsthis",
95 "If you press the <interface>Calculate</interface> button, the list will be updated "
96 "to all strings which are contained in the selected range and have the set minimum length.") );
97 mCalculateButton =
new KPushButton( updateGuiItem,
this );
98 mCalculateButton->setEnabled( mTool->
isApplyable() );
99 connect( mCalculateButton, SIGNAL(clicked(
bool)), SLOT(onCalculateClicked()) );
101 calculateLayout->addWidget( mCalculateButton );
102 baseLayout->addLayout( calculateLayout );
105 mChecksumLabel->setReadOnly(
true );
106 mChecksumLabel->setText( mTool->
checkSum() );
107 connect( mTool, SIGNAL(checksumChanged(QString)), mChecksumLabel, SLOT(setText(QString)) );
108 baseLayout->addWidget( mChecksumLabel, 10 );
110 baseLayout->addStretch( 10 );
112 connect( mTool, SIGNAL(uptodateChanged(
bool)), SLOT(onChecksumUptodateChanged(
bool)) );
113 connect( mTool, SIGNAL(isApplyableChanged(
bool)), SLOT(onApplyableChanged(
bool)) );
116 QAbstractItemView* algorithmComboBoxListView = mAlgorithmComboBox->view();
117 QObject::connect( algorithmComboBoxListView, SIGNAL(activated(QModelIndex)),
118 mParameterSetEditStack, SLOT(setFocus()) );
120 QObject::connect( algorithmComboBoxListView, SIGNAL(pressed(QModelIndex)),
121 mParameterSetEditStack, SLOT(setFocus()) );
127 void ChecksumView::addAlgorithms()
133 mAlgorithmComboBox->addItem( algorithm->
name() );
135 const char*
const parameterSetId = algorithm->
parameterSet()->
id();
139 mParameterSetEditStack->addWidget( parameterEdit );
149 if( parametersetEdit )
153 void ChecksumView::onCalculateClicked()
157 getParameterSet( parameterSet );
162 void ChecksumView::onOperationChange(
int index )
164 QWidget* oldWidget = mParameterSetEditStack->currentWidget();
167 oldWidget->disconnect(
this );
168 oldWidget->disconnect( mTool );
172 mParameterSetEditStack->setCurrentIndex( index );
176 if( parametersetEdit )
178 connect( parametersetEdit, SIGNAL(validityChanged(
bool)),
179 SLOT(onValidityChanged(
bool)) );
181 connect( parametersetEdit, SIGNAL(valuesChanged()),
182 mTool, SLOT(resetSourceTool()) );
183 onValidityChanged( parametersetEdit->
isValid() );
188 void ChecksumView::onChecksumUptodateChanged(
bool checksumUptodate )
191 mCalculateButton->setEnabled( ! checksumUptodate && isApplyable );
194 void ChecksumView::onApplyableChanged(
bool isApplyable )
196 mCalculateButton->setEnabled( !mTool->
isUptodate() && isApplyable );
199 void ChecksumView::onValidityChanged(
bool isValid )
201 mCalculateButton->setEnabled( mTool->
isApplyable() && isValid );
virtual AbstractByteArrayChecksumParameterSet * parameterSet()=0
used by the editor to get write access to the parameters
static AbstractByteArrayChecksumParameterSetEdit * createEdit(const char *id)
virtual bool isValid() const
default returns true
ChecksumView(ChecksumTool *tool, QWidget *parent=0)
virtual const char * id() const =0
virtual void getParameterSet(AbstractByteArrayChecksumParameterSet *parameterSet) const =0
default does nothing