32 #include <KMessageBox>
34 #include <QtGui/QLabel>
35 #include <QtGui/QLayout>
36 #include <QtGui/QCheckBox>
37 #include <QtGui/QTreeView>
38 #include <QtGui/QHeaderView>
39 #include <QtGui/QFocusEvent>
40 #include <QtGui/QFontMetrics>
49 mPODTableViewFocusChild( 0 )
51 QBoxLayout* baseLayout =
new QVBoxLayout(
this );
52 baseLayout->setMargin( 0 );
56 mPODTableView =
new QTreeView(
this );
57 mPODTableView->setObjectName( QLatin1String(
"PODTable" ) );
58 mPODTableView->setRootIsDecorated(
false );
59 mPODTableView->setAlternatingRowColors(
true );
60 mPODTableView->setItemsExpandable(
false );
61 mPODTableView->setUniformRowHeights(
true );
62 mPODTableView->setAllColumnsShowFocus(
true );
63 mPODTableView->setItemDelegate(
new PODDelegate(mTool,
this) );
64 mPODTableView->setEditTriggers( QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked );
65 mPODTableView->setDragEnabled(
true );
66 mPODTableView->setSortingEnabled(
false );
67 mPODTableView->setModel( mPODTableModel );
68 mPODTableView->installEventFilter(
this );
69 QHeaderView* header = mPODTableView->header();
70 header->setResizeMode( QHeaderView::Interactive );
71 header->setStretchLastSection(
false );
72 connect( mPODTableView->selectionModel(),
73 SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
74 SLOT(onCurrentRowChanged(QModelIndex,QModelIndex)) );
76 baseLayout->addWidget( mPODTableView, 10 );
79 QBoxLayout *settingsLayout =
new QHBoxLayout();
80 settingsLayout->setMargin( 0 );
82 mByteOrderSelection =
new KComboBox(
this );
83 mByteOrderSelection->addItem( i18nc(
"@item:inlistbox",
"Little-endian") );
84 mByteOrderSelection->addItem( i18nc(
"@item:inlistbox",
"Big-endian") );
85 mByteOrderSelection->setCurrentIndex( mTool->
byteOrder() );
86 connect( mByteOrderSelection, SIGNAL(activated(
int)),
87 mTool, SLOT(setByteOrder(
int)));
88 const QString byteOrderToolTip =
89 i18nc(
"@info:tooltip",
90 "The byte order to use for decoding the bytes." );
91 mByteOrderSelection->setToolTip( byteOrderToolTip );
92 settingsLayout->addWidget( mByteOrderSelection );
94 QLabel* unsignedAsHexLabel =
new QLabel( i18nc(
"@option:check",
"Unsigned as hexadecimal:"),
this );
95 settingsLayout->addWidget( unsignedAsHexLabel );
97 mUnsignedAsHexCheck =
new QCheckBox(
this );
99 connect( mUnsignedAsHexCheck, SIGNAL(toggled(
bool)),
100 mTool, SLOT(setUnsignedAsHex(
bool)) );
101 unsignedAsHexLabel->setBuddy( mUnsignedAsHexCheck );
102 const QString unsignedAsHexToolTip =
103 i18nc(
"@info:tooltip",
104 "Sets whether the values of the unsigned integer types are shown as hexadecimal instead of as decimal." );
105 unsignedAsHexLabel->setToolTip( unsignedAsHexToolTip );
106 mUnsignedAsHexCheck->setToolTip( unsignedAsHexToolTip );
107 settingsLayout->addWidget( mUnsignedAsHexCheck );
108 settingsLayout->addStretch();
110 baseLayout->addLayout( settingsLayout );
117 QFontMetrics metrics( f );
120 header->resizeSection( 0, metrics.width( QLatin1String(
"Hexadecimal 8-bit" ) ) + 30 );
121 header->resizeSection( 1, metrics.width( QLatin1String(
"1.01234567890123456789e-111" ) ) + 15 );
126 Q_UNUSED( sizeLeft );
130 int messageBoxAnswer;
131 if( newValueSize < oldValueSize )
133 const QString message =
135 "The new value needs <emphasis>fewer</emphasis> bytes (%1 instead of %2).<nl/>"
136 "Keep the unused bytes or remove them?", newValueSize, oldValueSize );
138 const KGuiItem keepGuiItem =
139 KGuiItem( i18nc(
"@action:button keep the unused bytes",
142 i18nc(
"@info:tooltip",
143 "Keep the unused bytes with their old values.") );
145 messageBoxAnswer = KMessageBox::warningYesNoCancel(
this, message, mTool->
title(),
147 KStandardGuiItem::remove() );
151 const QString message =
153 "The new value needs <emphasis>more</emphasis> bytes (%1 instead of %2).<nl/>"
154 "Overwrite the following bytes or insert new ones as needed?", newValueSize, oldValueSize );
156 messageBoxAnswer = KMessageBox::warningYesNoCancel(
this, message, mTool->
title(),
157 KStandardGuiItem::overwrite(),
158 KStandardGuiItem::insert() );
169 if(
object == mPODTableView )
171 if( event->type() == QEvent::FocusIn )
173 const QModelIndex current = mPODTableView->selectionModel()->currentIndex();
174 const int podId = current.row();
175 if( current.isValid() && mTool->
isApplyable() && ! mTool->
value(podId).isNull() )
178 else if( event->type() == QEvent::FocusOut )
180 QWidget* tableViewFocusWidget = mPODTableView->focusWidget();
181 const bool subChildHasFocus = ( tableViewFocusWidget != mPODTableView );
182 if( subChildHasFocus )
184 mPODTableViewFocusChild = tableViewFocusWidget;
185 mPODTableViewFocusChild->installEventFilter(
this );
191 else if(
object == mPODTableViewFocusChild )
194 if( event->type() == QEvent::FocusOut )
196 if( ! mPODTableView->hasFocus() && mTool->
isApplyable() )
198 mPODTableViewFocusChild->removeEventFilter(
this );
199 mPODTableViewFocusChild = 0;
203 return QWidget::eventFilter(
object, event );
206 void PODTableView::onCurrentRowChanged(
const QModelIndex& current,
const QModelIndex& previous )
210 if( ! mTool->isApplyable() )
213 const
int podId = current.row();
214 if( current.isValid() && ! mTool->value(podId).isNull() )
215 mTool->markPOD( podId );
virtual bool eventFilter(QObject *object, QEvent *event)
virtual Answer query(int newValueSize, int oldValueSize, int sizeLeft)
PODTableView(PODDecoderTool *tool, QWidget *parent=0)