AVT相机arm版本SDK

This commit is contained in:
zhangpeng
2025-04-30 09:26:04 +08:00
parent 837c870f18
commit 78a1c63a95
705 changed files with 148770 additions and 0 deletions

View File

@@ -0,0 +1,182 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraTreeWindow.cpp
Description: This is the main window of the Vimba Viewer that lists
all connected cameras.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "CameraTreeWindow.h"
#include <QHeaderView>
#include <QMenu>
CameraTreeWindow::CameraTreeWindow ( QWidget *parent ): QTreeWidget ( parent ), m_bIsChecked(true), m_bIsCheckboxClicked(false), m_bIsRightMouseClicked(false)
{
this->setHeaderLabel(tr("Detected Cameras"));
/* you need these three lines to show a H-scrollbar */
header()->setHorizontalScrollMode( QAbstractItemView::ScrollPerPixel );
header()->setResizeMode( 0, QHeaderView::ResizeToContents );
header()->setStretchLastSection( false );
connect(this, SIGNAL( itemClicked(QTreeWidgetItem *, int) ), this, SLOT( clickOnCamera(QTreeWidgetItem *, int)));
}
CameraTreeWindow::~CameraTreeWindow ( void )
{
}
QTreeWidgetItem *CameraTreeWindow::createItem ( void )
{
QTreeWidgetItem *item = new QTreeWidgetItem(this);
return item;
}
QTreeWidgetItem *CameraTreeWindow::createItem ( QTreeWidgetItem *itemRef, const bool &bIsCheckable )
{
QTreeWidgetItem *item = new QTreeWidgetItem(itemRef);
if(bIsCheckable)
{
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setCheckState( 0, Qt::Unchecked );
item->setWhatsThis(0, "camera");
}
return item;
}
void CameraTreeWindow::setText ( QTreeWidgetItem *itemRef, const QString &text )
{
itemRef->setText(0, text);
}
void CameraTreeWindow::setCheckCurrentItem ( const bool &bIsChecked )
{
if(bIsChecked)
m_CurrentItem->setCheckState(0, Qt::Checked);
else
m_CurrentItem->setCheckState(0, Qt::Unchecked);
}
void CameraTreeWindow::clickOnCamera ( QTreeWidgetItem *Item, int Column )
{
if(!this->isEnabled())
return;
m_CurrentItem = Item;
Qt::CheckState state = Item->checkState(0);
if(0 == Item->whatsThis(0).compare("camera"))
{
if(m_bIsCheckboxClicked)
{
this->setDisabled(true);
(Qt::Checked == state) ? emit cameraClicked(Item->text(0), true) : emit cameraClicked(Item->text(0), false);
}
else
{
if(Qt::Checked == state)
{
if(!m_bIsRightMouseClicked)
Item->setCheckState(0, Qt::Unchecked);
emit cameraClicked(Item->text(0), false);
}
else
{
if(!m_bIsRightMouseClicked)
Item->setCheckState(0, Qt::Checked);
emit cameraClicked(Item->text(0), true);
}
}
}
}
/* check where the click is going on
* By overwriting the mousePressEvent the slot clickOnCamera will be called afterwards
*/
void CameraTreeWindow::mousePressEvent ( QMouseEvent *event )
{
m_bIsCheckboxClicked = false;
QModelIndex clickedIndex = indexAt(event->pos());
/* make sure the event was on a valid item */
if (clickedIndex.isValid() == false)
return;
Qt::MouseButton mouseBtn = event->button();
if( Qt::RightButton == mouseBtn )
{
m_bIsRightMouseClicked = true;
emit rightMouseClicked (true);
}
else
{
m_bIsRightMouseClicked = false;
emit rightMouseClicked (false);
}
/* Get the tree widget's x position */
int treeX = header()->sectionViewportPosition(0);
/* Get the x coordinate of the root item. It is required in order to calculate
the identation of the item */
int rootX = visualRect(rootIndex()).x();
/* Get the rectangle of the viewport occupied by the pressed item */
QRect vrect = visualRect(clickedIndex);
/* Now we can easily calculate the x coordinate of the item */
int itemX = treeX + vrect.x() - rootX;
/* The item is a checkbox, then an icon and finally the text. */
/* 1. Get the rect surrounding the checkbox */
QRect checkboxRect = QRect(itemX,
vrect.y(),
style()->pixelMetric(QStyle::PM_IndicatorWidth)+3,
vrect.height()+2);
/* 2. Get the rect surrounding the icon */
QRect iconRect = QRect(itemX + checkboxRect.width(),
vrect.y(),
iconSize().width(),
vrect.height());
/* 3. Finally get the rect surrounding the text */
QRect textRect = QRect(itemX + checkboxRect.width() + iconRect.width(),
vrect.y(),
vrect.width() - checkboxRect.width() - iconRect.width(),
vrect.height());
/* Now check where the press event took place and handle it correspondingly */
if(checkboxRect.contains(event->pos()))
{
m_bIsCheckboxClicked = true;
}
QTreeWidget::mousePressEvent(event);
return;
}

View File

@@ -0,0 +1,75 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraTreeWindow.h
Description: This is the main window of the Vimba Viewer that
lists all connected cameras.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef CAMERATREEWINDOW_H
#define CAMERATREEWINDOW_H
#include <QTreeWidget>
#include <QMouseEvent>
#include "Helper.h"
class CameraTreeWindow : public QTreeWidget
{
Q_OBJECT
public:
protected:
private:
bool m_bIsChecked;
bool m_bIsCheckboxClicked;
bool m_bIsRightMouseClicked;
QTreeWidgetItem *m_CurrentItem;
public:
CameraTreeWindow ( QWidget *parent);
~CameraTreeWindow ( void );
QTreeWidgetItem *createItem ( void );
QTreeWidgetItem *createItem ( QTreeWidgetItem *itemRef, const bool &bIsCheckable );
void setText ( QTreeWidgetItem *itemRef, const QString &text );
void setCheckCurrentItem ( const bool &bIsChecked );
protected:
void mousePressEvent ( QMouseEvent *event );
private:
private slots:
void clickOnCamera ( QTreeWidgetItem *item, int column );
signals:
void cameraClicked ( const QString &sModel, const bool &bIsChecked );
void rightMouseClicked ( const bool &bIsClicked );
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,294 @@
/*=============================================================================
Copyright (C) 2012-2019 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ControllerTreeWindow.h
Description: All about features control tree
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef CONTROLLERTREEWINDOW_H
#define CONTROLLERTREEWINDOW_H
#include <QMap>
#include <QMutex>
#include <QTreeView>
#include <VimbaCPP/Include/IFeatureObserver.h>
using AVT::VmbAPI::FeaturePtr;
using AVT::VmbAPI::FeaturePtrVector;
using AVT::VmbAPI::CameraPtr;
using AVT::VmbAPI::IFeatureObserverPtr;
class ExComboBox;
class HexMainWindow;
class IntSpinBox;
class ItemDelegate;
class SortFilterProxyModel;
class MultiCompleter;
class QCheckBox;
class QHBoxLayout;
class QLabel;
class QLineEdit;
class QStandardItem;
class QStandardItemModel;
class QPushButton;
class QwtSlider;
class ControllerTreeWindow : public QTreeView
{
Q_OBJECT
public:
/* Filter Search Proxy */
SortFilterProxyModel *m_ProxyModel;
protected:
private:
FeaturePtrVector m_featPtrVec;
CameraPtr m_pCam;
MultiCompleter *m_StringCompleter;
ItemDelegate *m_TreeDelegate;
IFeatureObserverPtr m_pFeatureObs;
QString m_sCameraID;
VmbError_t m_ListTreeError;
QMap <QString, QString> m_DescriptonMap;
QMap <QString, QString> m_DisplayFeatureNameMap;
QMap <QString, FeaturePtr> m_featPtrMap;
QVector < QMap <QString, QString> > m_Level;
QMap <QString, QString> m_Level0Map;
QMap <QString, QString> m_Level1Map;
QMap <QString, QString> m_Level2Map;
QMap <QString, QString> m_Level3Map;
QMap <QString, QString> m_Level4Map;
QMap <QString, QString> m_Level5Map;
QMap <QString, QString> m_Level6Map;
QMap <QString, QString> m_Level7Map;
QMap <QString, QString> m_Level8Map;
QMap <QString, QString> m_Level9Map;
FeaturePtr m_FeaturePtr_Command;
FeaturePtr m_FeaturePtr_EnumComboBox;
FeaturePtr m_FeaturePtr_CheckBox;
FeaturePtr m_FeaturePtr_IntSpinBox;
FeaturePtr m_FeaturePtr_FloatSliderSpinBox;
FeaturePtr m_FeaturePtr_StringEditBox;
FeaturePtr m_FeaturePtr_LineEdit;
QString m_sFeature_Command;
QString m_sFeature_EnumComboBox;
QString m_sFeature_CheckBox;
QString m_sFeature_IntSpinBox;
QString m_sFeature_FloatSliderSpinBox;
QString m_sFeature_StringEditBox;
QString m_sFeature_StringLineEdit;
QString m_sCurrentSelectedFeature;
QStandardItemModel *m_Model;
QStandardItemModel *m_ModelGuru;
int m_nIntSliderOldValue;
unsigned int m_nSliderStep;
double m_dMinimum;
double m_dMaximum;
double m_dIncrement;
HexMainWindow *m_HexWindow;
std::vector <VmbUchar_t> m_RawData;
/* Logarithmic Slider */
QWidget *m_LogSliderWidget;
QwtSlider *m_LogSlider;
QHBoxLayout *m_HLogSliderLayout;
/* Button */
QPushButton *m_CmdButton;
QWidget *m_ButtonWidget;
QHBoxLayout *m_HButtonLayout;
QHBoxLayout *m_HButtonLayout2;
/* ComboBox */
ExComboBox *m_EnumComboBox;
QWidget *m_ComboWidget;
QHBoxLayout *m_HComboLayout;
QHBoxLayout *m_HComboLayout2;
/* Integer Feature Slider-SpinBoxes */
QWidget *m_IntSpinSliderWidget;
QHBoxLayout *m_HSpinSliderLayout_Int;
QHBoxLayout *m_HSpinSliderLayout_Int2;
IntSpinBox *m_SpinBox_Int;
QSlider *m_Slider_Int;
/* Float Feature Slider-Edit */
QWidget *m_FloatSliderEditWidget;
QHBoxLayout *m_HSpinSliderLayout_Float;
QHBoxLayout *m_HSliderEditLayout_Float2;
QLineEdit *m_EditBox_Float;
QwtSlider *m_Slider_Float;
/* String Feature EditBox */
QLineEdit *m_TextEdit_String;
QWidget *m_EditWidget;
QHBoxLayout *m_HEditLayout;
QHBoxLayout *m_HEditLayout2;
/* Boolean Feature CheckBox */
QCheckBox *m_CheckBox_Bool;
QWidget *m_BooleanWidget;
QHBoxLayout *m_HBooleanLayout;
QHBoxLayout *m_HBooleanLayout2;
/* IP Address or Direct Access */
QLineEdit *m_LineEdit;
QLabel *m_HexLabel;
QWidget *m_LineEditWidget;
QHBoxLayout *m_HLineEditLayout;
QHBoxLayout *m_HLineEditLayout2;
bool m_bIsTooltipOn;
QString m_sTooltip;
bool m_bIsJobDone;
bool m_bIsBusy;
bool m_bIsMousePressed;
/* GigE Auto adjust PacketSize */
bool m_bIsGigE;
bool m_bAutoAdjustPacketSize;
bool m_bIsTimeout;
QTimer *m_FeaturesPollingTimer;
QList <QString> m_FeaturesPollingName;
QMutex m_FeaturesPollingMutex;
public:
ControllerTreeWindow ( QString sID = " ", QWidget *parent = 0, bool bAutoAdjustPacketSize = false, CameraPtr pCam = CameraPtr() );
~ControllerTreeWindow ();
void setupTree ();
void synchronizeEventFeatures ();
VmbError_t getTreeStatus () const;
void showTooltip ( const bool bIsChecked );
void showControl ( const bool bIsShow );
void updateRegisterFeature ();
void updateUnRegisterFeature ();
bool isGigE() const;
MultiCompleter *getListCompleter() const;
void saveFeaturesToTextFile ( const QString &sDestPathAndFileName );
protected:
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
private:
void mapInformation (const QString sName, const FeaturePtr &featPtr);
QString getFeatureNameFromMap ( const QString &sDisplayName ) const;
bool findCategory ( const QMap <QString, QString>& map, const QString& sName) const;
unsigned int getGrandParentLevel( const QList<QStandardItem *>& items, const QString &sGrandParent) const;
bool isEventFeature ( const FeaturePtr pFeature ) const;
QString getFeatureValue ( const FeaturePtr &featPtr ) const;
QString getFeatureName ( const QModelIndex& item ) const;
void updateExpandedTreeValue ( const FeaturePtr &featPtr, const QString &sName );
bool registerFeatureObserver ( const QString &sFeatureName );
void unregisterFeatureObserver ( const QString &sFeatureName );
void resetControl ();
void sortCategoryAndAttribute ( const FeaturePtr &featPtr , QStandardItemModel *Model );
QString getFeatureInformation (const FeaturePtr &featPtr);
void createCommandButton ( const QModelIndex item ); /* maps to VmbFeatureDataCommand */
void createEnumComboBox ( const QModelIndex item ); /* maps to VmbFeatureDataEnum */
void createIntSliderSpinBox ( const QModelIndex item ); /* maps to VmbFeatureDataInt */
void createFloatSliderEditBox ( const QModelIndex item ); /* maps to VmbFeatureDataFloat */
void createBooleanCheckBox ( const QModelIndex item ); /* maps to VmbFeatureDataBool */
void createStringEditBox ( const QModelIndex item ); /* maps to VmbFeatureDataString */
void createHexEditor ( const QModelIndex item ); /* maps to VmbFeatureDataRaw*/
void createLineEdit ( const QModelIndex &item ); /* maps to register stuffs*/
void createLogarithmicSlider ( const QModelIndex &item ); /* maps to Exposure*/
void showIt ( const QModelIndex item, const QString &sWhat );
bool isFeatureWritable ( const QString &sFeature );
FeaturePtr getFeaturePtr ( const QString &sFeature );
void setIntegerValue ( const int &nValue );
void updateCurrentIntValue ();
void setFloatingValue ( const double &dValue );
void setLogarithmicFloatingValue( const double &dValue );
bool eventFilter (QObject *object, QEvent *event);
void onFloatSliderReleased ();
void onIntSliderReleased ();
void updateWidget ( const bool bIsWritable, const QVariant &value );
void onLogarithmicSliderReleased();
void AdjustOffscreenPosition (QPoint &position, QWidget &parentWidget );
public slots:
void closeControls(void);
protected slots:
void setAdjustPacketSizeTimeout ();
private Q_SLOTS:
void setLogarithmicSliderValue ( double v );
private slots:
void onClicked ( const QModelIndex & index );
void onCmdButtonClick ();
void onConfirmClick ();
void onIntSpinBoxClick ();
void onFloatEditFinished ();
void onIntSliderChanged ( int nValue );
void onFloatSliderChanged ( double dValue );
void onBoolCheckBoxClick ( bool bValue );
void onSetChangedFeature ( const QString &sFeature, const QString &sValue, const bool &bIsWritable );
void onSetEventMsg ( const QStringList &sMsg );
void onEnumComboBoxClick ( const QString &sSelected );
void expand ( const QModelIndex & index );
void collapse ( const QModelIndex & index );
void onLogarithmicFloatSpinBoxClick ();
void onEditText ();
void runPollingFeaturesValue ();
void pollingFeaturesValue ();
void updateColWidth ();
signals:
void setDescription ( const QString &sDesc );
void acquisitionStartStop ( const QString &sThisFeature );
void setEventMessage ( const QStringList &sMsg );
void logging ( const QString &sMessage );
void updateBufferSize ();
void resetFPS ();
void enableViewerMenu ( bool bIsEnabled);
};
#endif

View File

@@ -0,0 +1,42 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: DockWidgetWindow.cpp
Description: docking widget
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "DockWidgetWindow.h"
DockWidgetWindow::DockWidgetWindow ( const QString &sTitle, QWidget *parent ) : QDockWidget( sTitle, parent )
{
//this->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea|Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
QFont font;
font.setFamily(QString::fromUtf8("Verdana"));
this->setFont(font);
}
DockWidgetWindow::~DockWidgetWindow ( )
{
}

View File

@@ -0,0 +1,61 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: DockWidgetWindow.h
Description: docking widget
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef DOCKWIDGETWINDOW_H
#define DOCKWIDGETWINDOW_H
#include <QDockWidget>
#include "Helper.h"
class DockWidgetWindow : public QDockWidget
{
Q_OBJECT
public:
protected:
private:
public:
DockWidgetWindow ( const QString &sTitle, QWidget *parent = 0 );
~DockWidgetWindow ( void );
protected:
private:
private slots:
signals:
};
#endif

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ExComboBox.cpp
Description: When you do a fast switch on feature tree while ComboBox has just opened, the LineEdit won<6F>t be deleted (Qt BUG!),
and it still shows up even the combo object has been deleted. To avoid this just make sure to hide popup when destroying combo object.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "ExComboBox.h"
ExComboBox::ExComboBox ( QWidget *parent ): QComboBox ( parent )
{
}
ExComboBox::~ExComboBox ( void )
{
QComboBox::showPopup();
QComboBox::hidePopup();
}
void ExComboBox::showPopup ()
{
QComboBox::showPopup();
}
void ExComboBox::hidePopup ()
{
QComboBox::hidePopup();
}

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ComboBox.h
Description: When you do a fast switch on feature tree while ComboBox has just opened, the LineEdit won<6F>t be deleted (Qt BUG!),
and it still shows up even the combo object has been deleted. To avoid this just make sure to hide popup when destroying combo object.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef EXCOMBOBOX_H
#define EXCOMBOBOX_H
#include <QComboBox>
class ExComboBox : public QComboBox
{
Q_OBJECT
public:
protected:
private:
virtual void showPopup ();
virtual void hidePopup ();
public:
ExComboBox ( QWidget *parent = 0);
~ExComboBox ( void );
protected:
private:
};
#endif

View File

@@ -0,0 +1,60 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FloatSpinBox.cpp
Description: Spinbox to handle floating feature
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "FloatSpinBox.h"
FloatSpinBox::FloatSpinBox ( QWidget *parent ): QDoubleSpinBox ( parent )
{
}
FloatSpinBox::~FloatSpinBox ( void )
{
}
void FloatSpinBox::stepBy( int steps )
{
double dInterval = singleStep();
double dValue = value();
if( (minimum() > value()) || (maximum() < value()) )
return;
if(0 < steps ) //stepUp
{
setValue( dValue+dInterval);
}
else //stepDown
{
setValue( dValue-dInterval);
}
editingFinished();
}

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FloatSpinBox.h
Description: Spinbox to handle floating feature
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef FLOATSPINBOX_H
#define FLOATSPINBOX_H
#include <QSpinBox>
class FloatSpinBox : public QDoubleSpinBox
{
Q_OBJECT
public:
protected:
private:
public:
FloatSpinBox ( QWidget *parent );
~FloatSpinBox ( void );
protected:
private:
virtual void stepBy ( int steps );
};
#endif

View File

@@ -0,0 +1,138 @@
/*
| ==============================================================================
| Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
| This code may be used in part, or in whole for your application development.
|
|==============================================================================
|
| THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
| NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
| DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
| INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
| OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
| LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| http://code.google.com/p/qhexedit2/
|==============================================================================
*/
#include "Commands.h"
CharCommand::CharCommand(XByteArray * xData, Cmd cmd, int charPos, char newChar, QUndoCommand *parent)
: QUndoCommand(parent)
{
m_xData = xData;
m_CharPos = charPos;
m_NewChar = newChar;
m_Cmd = cmd;
}
bool CharCommand::mergeWith(const QUndoCommand *command)
{
const CharCommand *nextCommand = static_cast<const CharCommand *>(command);
bool result = false;
if (m_Cmd != remove)
{
if (nextCommand->m_Cmd == replace)
if (nextCommand->m_CharPos == m_CharPos)
{
m_NewChar = nextCommand->m_NewChar;
result = true;
}
}
return result;
}
void CharCommand::undo()
{
switch (m_Cmd)
{
case insert:
m_xData->remove(m_CharPos, 1);
break;
case replace:
m_xData->replace(m_CharPos, m_OldChar);
m_xData->setDataChanged(m_CharPos, m_WasChanged);
break;
case remove:
m_xData->insert(m_CharPos, m_OldChar);
m_xData->setDataChanged(m_CharPos, m_WasChanged);
break;
}
}
void CharCommand::redo()
{
switch (m_Cmd)
{
case insert:
m_xData->insert(m_CharPos, m_NewChar);
break;
case replace:
m_OldChar = m_xData->data()[m_CharPos];
m_WasChanged = m_xData->dataChanged(m_CharPos);
m_xData->replace(m_CharPos, m_NewChar);
break;
case remove:
m_OldChar = m_xData->data()[m_CharPos];
m_WasChanged = m_xData->dataChanged(m_CharPos);
m_xData->remove(m_CharPos, 1);
break;
}
}
ArrayCommand::ArrayCommand(XByteArray * xData, Cmd cmd, int baPos, QByteArray newBa, int len, QUndoCommand *parent)
: QUndoCommand(parent)
{
m_Cmd = cmd;
m_xData = xData;
m_ByteArrayPos = baPos;
m_NewByteArray = newBa;
m_Length = len;
}
void ArrayCommand::undo()
{
switch (m_Cmd)
{
case insert:
m_xData->remove(m_ByteArrayPos, m_NewByteArray.length());
break;
case replace:
m_xData->replace(m_ByteArrayPos, m_OldByteArray);
m_xData->setDataChanged(m_ByteArrayPos, m_WasChanged);
break;
case remove:
m_xData->insert(m_ByteArrayPos, m_OldByteArray);
m_xData->setDataChanged(m_ByteArrayPos, m_WasChanged);
break;
}
}
void ArrayCommand::redo()
{
switch (m_Cmd)
{
case insert:
m_xData->insert(m_ByteArrayPos, m_NewByteArray);
break;
case replace:
m_OldByteArray = m_xData->data().mid(m_ByteArrayPos, m_Length);
m_WasChanged = m_xData->dataChanged(m_ByteArrayPos, m_Length);
m_xData->replace(m_ByteArrayPos, m_NewByteArray);
break;
case remove:
m_OldByteArray = m_xData->data().mid(m_ByteArrayPos, m_Length);
m_WasChanged = m_xData->dataChanged(m_ByteArrayPos, m_Length);
m_xData->remove(m_ByteArrayPos, m_Length);
break;
}
}

View File

@@ -0,0 +1,70 @@
#ifndef COMMANDS_H
#define COMMANDS_H
/** \cond docNever */
#include <QUndoCommand>
#include "XByteArray.h"
/*! CharCommand is a class to prived undo/redo functionality in QHexEdit.
A QUndoCommand represents a single editing action on a document. CharCommand
is responsable for manipulations on single chars. It can insert. replace and
remove characters. A manipulation stores allways to actions
1. redo (or do) action
2. undo action.
CharCommand also supports command compression via mergeWidht(). This allows
the user to execute a undo command contation e.g. 3 steps in a single command.
If you for example insert a new byt "34" this means for the editor doing 3
steps: insert a "00", replace it with "03" and the replace it with "34". These
3 steps are combined into a single step, insert a "34".
*/
class CharCommand : public QUndoCommand
{
public:
enum { Id = 1234 };
enum Cmd {insert, remove, replace};
CharCommand(XByteArray * xData, Cmd cmd, int charPos, char newChar,
QUndoCommand *parent=0);
void undo();
void redo();
bool mergeWith(const QUndoCommand *command);
int id() const { return Id; }
private:
XByteArray *m_xData;
int m_CharPos;
bool m_WasChanged;
char m_NewChar;
char m_OldChar;
Cmd m_Cmd;
};
/*! ArrayCommand provides undo/redo functionality for handling binary strings. It
can undo/redo insert, replace and remove binary strins (QByteArrays).
*/
class ArrayCommand : public QUndoCommand
{
public:
enum Cmd {insert, remove, replace};
ArrayCommand(XByteArray * xData, Cmd cmd, int baPos, QByteArray newBa=QByteArray(), int len=0,
QUndoCommand *parent=0);
void undo();
void redo();
private:
Cmd m_Cmd;
XByteArray *m_xData;
int m_ByteArrayPos;
int m_Length;
QByteArray m_WasChanged;
QByteArray m_NewByteArray;
QByteArray m_OldByteArray;
};
/** \endcond docNever */
#endif // COMMANDS_H

View File

@@ -0,0 +1,224 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HexMainWindow.cpp
Description: a hex editor to show raw data
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "HexMainWindow.h"
HexMainWindow::HexMainWindow ( QWidget *parent, Qt::WindowFlags flag, QString sID, bool bIsReadOnly, FeaturePtr featPtr ) : QMainWindow( parent, flag )
{
m_RawDataFeatPtr = featPtr;
setWindowModality(Qt::WindowModal);
std::string sFeatureDisplayName;
m_RawDataFeatPtr->GetDisplayName(sFeatureDisplayName);
setWindowTitle(sID.append(" <").append(QString::fromStdString(sFeatureDisplayName)).append(">"));
init();
QPoint p = QCursor::pos();
readSettings();
move(p.x()-100, p.y()-100);
m_HexEdit->setReadOnly(bIsReadOnly);
show();
}
HexMainWindow::~HexMainWindow ( void )
{
}
void HexMainWindow::closeEvent(QCloseEvent *)
{
writeSettings();
}
void HexMainWindow::settingsAccepted()
{
writeSettings();
readSettings();
}
void HexMainWindow::save()
{
saveFile();
}
void HexMainWindow::setAddress(int address)
{
m_LbAddress->setText(QString("%1").arg(address, 1, 16));
}
void HexMainWindow::setOverwriteMode(bool mode)
{
if (mode)
m_LbOverwriteMode->setText(tr("Overwrite"));
else
m_LbOverwriteMode->setText(tr("Insert"));
}
void HexMainWindow::setSize(int size)
{
m_LbSize->setText(QString("%1").arg(size));
}
void HexMainWindow::showOptionsDialog()
{
m_OptionsDialog->show();
}
void HexMainWindow::init()
{
setAttribute(Qt::WA_DeleteOnClose);
m_OptionsDialog = new HexOptionDialog(this);
m_OptionsDialog->setWindowFlags(m_OptionsDialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(m_OptionsDialog, SIGNAL(accepted()), this, SLOT(settingsAccepted()));
m_HexEdit = new QHexEdit;
setCentralWidget(m_HexEdit);
connect(m_HexEdit, SIGNAL(overwriteModeChanged(bool)), this, SLOT(setOverwriteMode(bool)));
createActions();
createMenus();
createToolBars();
createStatusBar();
setUnifiedTitleAndToolBarOnMac(true);
}
void HexMainWindow::createActions()
{
m_SaveAct = new QAction(QIcon(":/VimbaViewer/Images/save.png"), tr("&Save"), this);
m_SaveAct->setShortcuts(QKeySequence::Save);
m_SaveAct->setStatusTip(tr("Save data to buffer"));
connect(m_SaveAct, SIGNAL(triggered()), this, SLOT(save()));
m_OptionsAct = new QAction(QIcon(":/VimbaViewer/Images/option.png"), tr("Se&ttings"), this);
m_OptionsAct->setStatusTip(tr("Show the Dialog to select editor options"));
connect(m_OptionsAct, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));
}
void HexMainWindow::createMenus()
{
m_FileMenu = menuBar()->addMenu(tr("&File"));
m_FileMenu->addAction(m_SaveAct);
m_EditMenu = menuBar()->addMenu(tr("&Edit"));
m_EditMenu->addAction(m_OptionsAct);
}
void HexMainWindow::createStatusBar()
{
// Address Label
m_LbAddressName = new QLabel();
m_LbAddressName->setText(tr("Address:"));
statusBar()->addPermanentWidget(m_LbAddressName);
m_LbAddress = new QLabel();
m_LbAddress->setFrameShape(QFrame::Panel);
m_LbAddress->setFrameShadow(QFrame::Sunken);
m_LbAddress->setMinimumWidth(70);
statusBar()->addPermanentWidget(m_LbAddress);
connect(m_HexEdit, SIGNAL(currentAddressChanged(int)), this, SLOT(setAddress(int)));
// Size Label
m_LbSizeName = new QLabel();
m_LbSizeName->setText(tr("Size:"));
statusBar()->addPermanentWidget(m_LbSizeName);
m_LbSize = new QLabel();
m_LbSize->setFrameShape(QFrame::Panel);
m_LbSize->setFrameShadow(QFrame::Sunken);
m_LbSize->setMinimumWidth(70);
statusBar()->addPermanentWidget(m_LbSize);
connect(m_HexEdit, SIGNAL(currentSizeChanged(int)), this, SLOT(setSize(int)));
// Overwrite Mode Label
m_LbOverwriteModeName = new QLabel();
m_LbOverwriteModeName->setText(tr("Mode:"));
statusBar()->addPermanentWidget(m_LbOverwriteModeName);
m_LbOverwriteMode = new QLabel();
m_LbOverwriteMode->setFrameShape(QFrame::Panel);
m_LbOverwriteMode->setFrameShadow(QFrame::Sunken);
m_LbOverwriteMode->setMinimumWidth(70);
statusBar()->addPermanentWidget(m_LbOverwriteMode);
setOverwriteMode(m_HexEdit->overwriteMode());
statusBar()->showMessage(tr("Ready"));
}
void HexMainWindow::createToolBars()
{
m_FileToolBar = addToolBar(tr("File"));
m_FileToolBar->addAction(m_SaveAct);
}
void HexMainWindow::setData (const QByteArray &array)
{
m_HexEdit->setData(array);
QApplication::restoreOverrideCursor();
}
void HexMainWindow::readSettings()
{
QSettings settings("Allied Vision", "Vimba Viewer");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(610, 460)).toSize();
move(pos);
resize(size);
m_HexEdit->setAddressArea(settings.value("AddressArea").toBool());
m_HexEdit->setAsciiArea(settings.value("AsciiArea").toBool());
m_HexEdit->setHighlighting(settings.value("Highlighting").toBool());
m_HexEdit->setOverwriteMode(settings.value("OverwriteMode").toBool());
m_HexEdit->setReadOnly(settings.value("ReadOnly").toBool());
m_HexEdit->setHighlightingColor(settings.value("HighlightingColor").value<QColor>());
m_HexEdit->setAddressAreaColor(settings.value("AddressAreaColor").value<QColor>());
m_HexEdit->setSelectionColor(settings.value("SelectionColor").value<QColor>());
m_HexEdit->setFont(settings.value("WidgetFont").value<QFont>());
m_HexEdit->setAddressWidth(settings.value("AddressAreaWidth").toInt());
}
void HexMainWindow::saveFile( void )
{
std::vector <VmbUchar_t> v;
for(int i=0; i < m_HexEdit->data().size(); i++)
{
v.push_back(m_HexEdit->data().at(i));
}
VmbError_t error = m_RawDataFeatPtr->SetValue(v);
if(VmbErrorSuccess != error)
{
QMessageBox::critical(this, tr("VimbaViewer"), tr("writing data to camera FAILED"));
}
}
void HexMainWindow::writeSettings()
{
QSettings settings("Allied Vision", "Vimba Viewer");
settings.setValue("pos", pos());
settings.setValue("size", size());
}

View File

@@ -0,0 +1,98 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HexMainWindow.h
Description: a hex editor to show raw data
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef HEXMAINWINDOW_H
#define HEXMAINWINDOW_H
#include "QHexEdit.h"
#include "HexOptionDialog.h"
#include <QMainWindow>
QT_BEGIN_NAMESPACE
class QAction;
class QMenu;
class QUndoStack;
QT_END_NAMESPACE
#include <VimbaCPP/Include/VimbaSystem.h>
using AVT::VmbAPI::FeaturePtr;
class HexMainWindow : public QMainWindow
{
Q_OBJECT
protected:
private:
FeaturePtr m_RawDataFeatPtr;
public:
HexMainWindow ( QWidget *parent = 0, Qt::WindowFlags flag = 0, QString sID = " ", bool bIsReadOnly = false, FeaturePtr featPtr = FeaturePtr() );
~HexMainWindow ( void );
void setData (const QByteArray &array);
protected:
void closeEvent(QCloseEvent *event);
private:
void init();
void createActions();
void createMenus();
void createStatusBar();
void createToolBars();
void readSettings();
void saveFile(void);
void writeSettings();
QMenu *m_FileMenu;
QMenu *m_EditMenu;
QToolBar *m_FileToolBar;
QAction *m_SaveAct;
QAction *m_OptionsAct;
QHexEdit *m_HexEdit;
HexOptionDialog *m_OptionsDialog;
QLabel *m_LbAddress, *m_LbAddressName;
QLabel *m_LbOverwriteMode, *m_LbOverwriteModeName;
QLabel *m_LbSize, *m_LbSizeName;
private slots:
void settingsAccepted();
void save( void);
void setAddress(int address);
void setOverwriteMode(bool mode);
void setSize(int size);
void showOptionsDialog();
};
#endif

View File

@@ -0,0 +1,121 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HexOptionDialog.cpp
Description: a setting dialog for hex editor
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "HexOptionDialog.h"
#include "ui_OptionDialog.h"
HexOptionDialog::HexOptionDialog ( QWidget *parent) : QDialog( parent ), ui(new Ui::OptionDialog)
{
ui->setupUi(this);
readSettings();
writeSettings();
}
HexOptionDialog::~HexOptionDialog ( void )
{
delete ui;
}
void HexOptionDialog::accept()
{
writeSettings();
emit accepted();
QDialog::hide();
}
void HexOptionDialog::readSettings()
{
QSettings settings("Allied Vision", "Vimba Viewer");
ui->cbAddressArea->setChecked(settings.value("AddressArea", true).toBool());
ui->cbAsciiArea->setChecked(settings.value("AsciiArea", true).toBool());
ui->cbHighlighting->setChecked(settings.value("Highlighting", true).toBool());
ui->cbOverwriteMode->setChecked(settings.value("OverwriteMode", true).toBool());
ui->cbReadOnly->setChecked(settings.value("ReadOnly").toBool());
setColor(ui->lbHighlightingColor, settings.value("HighlightingColor", QColor(0xff, 0xff, 0x99, 0xff)).value<QColor>());
setColor(ui->lbAddressAreaColor, settings.value("AddressAreaColor", QColor(0xd4, 0xd4, 0xd4, 0xff)).value<QColor>());
setColor(ui->lbSelectionColor, settings.value("SelectionColor", QColor(0x6d, 0x9e, 0xff, 0xff)).value<QColor>());
ui->leWidgetFont->setFont(settings.value("WidgetFont", QFont("Courier", 10)).value<QFont>());
ui->sbAddressAreaWidth->setValue(settings.value("AddressAreaWidth", 4).toInt());
}
void HexOptionDialog::writeSettings()
{
QSettings settings("Allied Vision", "Vimba Viewer");
settings.setValue("AddressArea", ui->cbAddressArea->isChecked());
settings.setValue("AsciiArea", ui->cbAsciiArea->isChecked());
settings.setValue("Highlighting", ui->cbHighlighting->isChecked());
settings.setValue("OverwriteMode", ui->cbOverwriteMode->isChecked());
settings.setValue("ReadOnly", ui->cbReadOnly->isChecked());
settings.setValue("HighlightingColor", ui->lbHighlightingColor->palette().color(QPalette::Background));
settings.setValue("AddressAreaColor", ui->lbAddressAreaColor->palette().color(QPalette::Background));
settings.setValue("SelectionColor", ui->lbSelectionColor->palette().color(QPalette::Background));
settings.setValue("WidgetFont",ui->leWidgetFont->font());
settings.setValue("AddressAreaWidth", ui->sbAddressAreaWidth->value());
}
void HexOptionDialog::setColor(QWidget *widget, QColor color)
{
QPalette palette = widget->palette();
palette.setColor(QPalette::Background, color);
widget->setPalette(palette);
widget->setAutoFillBackground(true);
}
void HexOptionDialog::on_pbHighlightingColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbHighlightingColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbHighlightingColor, color);
}
void HexOptionDialog::on_pbAddressAreaColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbAddressAreaColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbAddressAreaColor, color);
}
void HexOptionDialog::on_pbSelectionColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbSelectionColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbSelectionColor, color);
}
void HexOptionDialog::on_pbWidgetFont_clicked()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, ui->leWidgetFont->font(), this);
if (ok)
ui->leWidgetFont->setFont(font);
}

View File

@@ -0,0 +1,64 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HexOptionDialog.cpp
Description: a setting dialog for hex editor
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef HEXOPTIONDIALOG_H
#define HEXOPTIONDIALOG_H
#include <QtCore>
#include <QtGui>
namespace Ui {
class OptionDialog;
}
class HexOptionDialog : public QDialog
{
Q_OBJECT
public:
explicit HexOptionDialog(QWidget *parent = 0);
~HexOptionDialog();
Ui::OptionDialog *ui;
public slots:
virtual void accept();
private slots:
void on_pbHighlightingColor_clicked();
void on_pbAddressAreaColor_clicked();
void on_pbSelectionColor_clicked();
void on_pbWidgetFont_clicked();
private:
void readSettings();
void writeSettings();
void setColor(QWidget *widget, QColor color);
};
#endif

View File

@@ -0,0 +1,286 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OptionDialog</class>
<widget class="QDialog" name="OptionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>395</width>
<height>427</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="gbFlags">
<property name="title">
<string>Flags</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<widget class="QCheckBox" name="cbReadOnly">
<property name="text">
<string>ReadOnly</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cbHighlighting">
<property name="text">
<string>Highlighting</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="cbOverwriteMode">
<property name="text">
<string>Overwrite Mode</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="cbAddressArea">
<property name="text">
<string>Address Area</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="cbAsciiArea">
<property name="text">
<string>Ascii Area</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbColors">
<property name="title">
<string>Colors and Fonts</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="pbHighlightingColor">
<property name="text">
<string>Highlighting Color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lbHighlightingColor">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0" rowspan="2">
<widget class="QPushButton" name="pbAddressAreaColor">
<property name="text">
<string>Address Area Color</string>
</property>
</widget>
</item>
<item row="1" column="1" rowspan="2">
<widget class="QLabel" name="lbAddressAreaColor">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lbSelectionColor">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pbSelectionColor">
<property name="text">
<string>Selection Color</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pbWidgetFont">
<property name="text">
<string>Widget Font</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="leWidgetFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>01 23 45 67 89 ab cd ef</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbAddressAreaWidth">
<property name="title">
<string>Address Area</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="lbAddressAreaWidth">
<property name="text">
<string>Address Area Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="sbAddressAreaWidth">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4</number>
</property>
<property name="value">
<number>4</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>28</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>pbHighlightingColor</tabstop>
<tabstop>pbAddressAreaColor</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>OptionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>222</x>
<y>154</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>168</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>OptionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>290</x>
<y>160</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>168</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,203 @@
/*
| ==============================================================================
| Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
| This code may be used in part, or in whole for your application development.
|
|==============================================================================
|
| THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
| NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
| DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
| INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
| OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
| LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| http://code.google.com/p/qhexedit2/
|==============================================================================
*/
#include <QtGui>
#include "QHexEdit.h"
QHexEdit::QHexEdit(QWidget *parent) : QScrollArea(parent)
{
m_qHexEdit_p = new QHexEditPrivate(this);
setWidget(m_qHexEdit_p);
setWidgetResizable(true);
connect(m_qHexEdit_p, SIGNAL(currentAddressChanged(int)), this, SIGNAL(currentAddressChanged(int)));
connect(m_qHexEdit_p, SIGNAL(currentSizeChanged(int)), this, SIGNAL(currentSizeChanged(int)));
connect(m_qHexEdit_p, SIGNAL(dataChanged()), this, SIGNAL(dataChanged()));
connect(m_qHexEdit_p, SIGNAL(overwriteModeChanged(bool)), this, SIGNAL(overwriteModeChanged(bool)));
setFocusPolicy(Qt::NoFocus);
}
int QHexEdit::indexOf(const QByteArray & ba, int from) const
{
return m_qHexEdit_p->indexOf(ba, from);
}
void QHexEdit::insert(int i, const QByteArray & ba)
{
m_qHexEdit_p->insert(i, ba);
}
void QHexEdit::insert(int i, char ch)
{
m_qHexEdit_p->insert(i, ch);
}
int QHexEdit::lastIndexOf(const QByteArray & ba, int from) const
{
return m_qHexEdit_p->lastIndexOf(ba, from);
}
void QHexEdit::remove(int pos, int len)
{
m_qHexEdit_p->remove(pos, len);
}
void QHexEdit::replace( int pos, int len, const QByteArray & after)
{
m_qHexEdit_p->replace(pos, len, after);
}
QString QHexEdit::toReadableString()
{
return m_qHexEdit_p->toRedableString();
}
QString QHexEdit::selectionToReadableString()
{
return m_qHexEdit_p->selectionToReadableString();
}
void QHexEdit::setAddressArea(bool addressArea)
{
m_qHexEdit_p->setAddressArea(addressArea);
}
void QHexEdit::redo()
{
m_qHexEdit_p->redo();
}
void QHexEdit::undo()
{
m_qHexEdit_p->undo();
}
void QHexEdit::setAddressWidth(int addressWidth)
{
m_qHexEdit_p->setAddressWidth(addressWidth);
}
void QHexEdit::setAsciiArea(bool asciiArea)
{
m_qHexEdit_p->setAsciiArea(asciiArea);
}
void QHexEdit::setHighlighting(bool mode)
{
m_qHexEdit_p->setHighlighting(mode);
}
void QHexEdit::setAddressOffset(int offset)
{
m_qHexEdit_p->setAddressOffset(offset);
}
int QHexEdit::addressOffset()
{
return m_qHexEdit_p->addressOffset();
}
void QHexEdit::setCursorPosition(int cursorPos)
{
// cursorPos in QHexEditPrivate is the position of the textcoursor without
// blanks, means bytePos*2
m_qHexEdit_p->setCursorPos(cursorPos*2);
}
int QHexEdit::cursorPosition()
{
return m_qHexEdit_p->cursorPos() / 2;
}
void QHexEdit::setData(const QByteArray &data)
{
m_qHexEdit_p->setData(data);
}
QByteArray QHexEdit::data()
{
return m_qHexEdit_p->data();
}
void QHexEdit::setAddressAreaColor(const QColor &color)
{
m_qHexEdit_p->setAddressAreaColor(color);
}
QColor QHexEdit::addressAreaColor()
{
return m_qHexEdit_p->addressAreaColor();
}
void QHexEdit::setHighlightingColor(const QColor &color)
{
m_qHexEdit_p->setHighlightingColor(color);
}
QColor QHexEdit::highlightingColor()
{
return m_qHexEdit_p->highlightingColor();
}
void QHexEdit::setSelectionColor(const QColor &color)
{
m_qHexEdit_p->setSelectionColor(color);
}
QColor QHexEdit::selectionColor()
{
return m_qHexEdit_p->selectionColor();
}
void QHexEdit::setOverwriteMode(bool overwriteMode)
{
m_qHexEdit_p->setOverwriteMode(overwriteMode);
}
bool QHexEdit::overwriteMode()
{
return m_qHexEdit_p->overwriteMode();
}
void QHexEdit::setReadOnly(bool readOnly)
{
m_qHexEdit_p->setReadOnly(readOnly);
}
bool QHexEdit::isReadOnly()
{
return m_qHexEdit_p->isReadOnly();
}
void QHexEdit::setFont(const QFont &font)
{
m_qHexEdit_p->setFont(font);
}
const QFont & QHexEdit::font() const
{
return m_qHexEdit_p->font();
}

View File

@@ -0,0 +1,236 @@
#ifndef QHEXEDIT_H
#define QHEXEDIT_H
#include <QtGui>
#include "QHexEdit_p.h"
/** \mainpage
QHexEdit is a binary editor widget for Qt.
\version Version 0.6.3
\image html hexedit.png
*/
/*! QHexEdit is a hex editor widget written in C++ for the Qt (Qt4) framework.
It is a simple editor for binary data, just like QPlainTextEdit is for text
data. There are sip configuration files included, so it is easy to create
bindings for PyQt and you can use this widget also in python.
QHexEdit takes the data of a QByteArray (setData()) and shows it. You can use
the mouse or the keyboard to navigate inside the widget. If you hit the keys
(0..9, a..f) you will change the data. Changed data is highlighted and can be
accessed via data().
Normaly QHexEdit works in the overwrite Mode. You can set overwriteMode(false)
and insert data. In this case the size of data() increases. It is also possible
to delete bytes (del or backspace), here the size of data decreases.
You can select data with keyboard hits or mouse movements. The copy-key will
copy the selected data into the clipboard. The cut-key copies also but delets
it afterwards. In overwrite mode, the paste function overwrites the content of
the (does not change the length) data. In insert mode, clipboard data will be
inserted. The clipboard content is expected in ASCII Hex notation. Unknown
characters will be ignored.
QHexEdit comes with undo/redo functionality. All changes can be undone, by
pressing the undo-key (usually ctr-z). They can also be redone afterwards.
The undo/redo framework is cleared, when setData() sets up a new
content for the editor. You can search data inside the content with indexOf()
and lastIndexOf(). The replace() function is to change located subdata. This
'replaced' data can also be undone by the undo/redo framework.
This widget can only handle small amounts of data. The size has to be below 10
megabytes, otherwise the scroll sliders ard not shown and you can't scroll any
more.
*/
class QHexEdit : public QScrollArea
{
Q_OBJECT
/*! Property data holds the content of QHexEdit. Call setData() to set the
content of QHexEdit, data() returns the actual content.
*/
Q_PROPERTY(QByteArray data READ data WRITE setData)
/*! Property addressOffset is added to the Numbers of the Address Area.
A offset in the address area (left side) is sometimes usefull, whe you show
only a segment of a complete memory picture. With setAddressOffset() you set
this property - with addressOffset() you get the actual value.
*/
Q_PROPERTY(int addressOffset READ addressOffset WRITE setAddressOffset)
/*! Property address area color sets (setAddressAreaColor()) the backgorund
color of address areas. You can also read the color (addressaAreaColor()).
*/
Q_PROPERTY(QColor addressAreaColor READ addressAreaColor WRITE setAddressAreaColor)
/*! Porperty cursorPosition sets or gets the position of the editor cursor
in QHexEdit.
*/
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
/*! Property highlighting color sets (setHighlightingColor()) the backgorund
color of highlighted text areas. You can also read the color
(highlightingColor()).
*/
Q_PROPERTY(QColor highlightingColor READ highlightingColor WRITE setHighlightingColor)
/*! Property selection color sets (setSelectionColor()) the backgorund
color of selected text areas. You can also read the color
(selectionColor()).
*/
Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor)
/*! Porperty overwrite mode sets (setOverwriteMode()) or gets (overwriteMode()) the mode
in which the editor works. In overwrite mode the user will overwrite existing data. The
size of data will be constant. In insert mode the size will grow, when inserting
new data.
*/
Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
/*! Porperty readOnly sets (setReadOnly()) or gets (isReadOnly) the mode
in which the editor works. In readonly mode the the user can only navigate
through the data and select data; modifying is not possible. This
property's default is false.
*/
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
/*! Set the font of the widget. Please use fixed width fonts like Mono or Courier.*/
Q_PROPERTY(QFont font READ font WRITE setFont)
public:
/*! Creates an instance of QHexEdit.
\param parent Parent widget of QHexEdit.
*/
QHexEdit(QWidget *parent = 0);
/*! Returns the index position of the first occurrence
of the byte array ba in this byte array, searching forward from index position
from. Returns -1 if ba could not be found. In addition to this functionality
of QByteArray the cursorposition is set to the end of found bytearray and
it will be selected.
*/
int indexOf(const QByteArray & ba, int from = 0) const;
/*! Inserts a byte array.
\param i Index position, where to insert
\param ba byte array, which is to insert
In overwrite mode, the existing data will be overwritten, in insertmode ba will be
inserted and size of data grows.
*/
void insert(int i, const QByteArray & ba);
/*! Inserts a char.
\param i Index position, where to insert
\param ch Char, which is to insert
In overwrite mode, the existing data will be overwritten, in insertmode ba will be
inserted and size of data grows.
*/
void insert(int i, char ch);
/*! Returns the index position of the last occurrence
of the byte array ba in this byte array, searching backwards from index position
from. Returns -1 if ba could not be found. In addition to this functionality
of QByteArray the cursorposition is set to the beginning of found bytearray and
it will be selected.
*/
int lastIndexOf(const QByteArray & ba, int from = 0) const;
/*! Removes len bytes from the content.
\param pos Index position, where to remove
\param len Amount of bytes to remove
In overwrite mode, the existing bytes will be overwriten with 0x00.
*/
void remove(int pos, int len=1);
/*! Replaces len bytes from index position pos with the byte array after.
*/
void replace( int pos, int len, const QByteArray & after);
/*! Gives back a formatted image of the content of QHexEdit
*/
QString toReadableString();
/*! Gives back a formatted image of the selected content of QHexEdit
*/
QString selectionToReadableString();
/*! \cond docNever */
void setAddressOffset(int offset);
int addressOffset();
void setCursorPosition(int cusorPos);
int cursorPosition();
void setData(QByteArray const &data);
QByteArray data();
void setAddressAreaColor(QColor const &color);
QColor addressAreaColor();
void setHighlightingColor(QColor const &color);
QColor highlightingColor();
void setSelectionColor(QColor const &color);
QColor selectionColor();
void setOverwriteMode(bool);
bool overwriteMode();
void setReadOnly(bool);
bool isReadOnly();
const QFont &font() const;
void setFont(const QFont &);
/*! \endcond docNever */
public slots:
/*! Redoes the last operation. If there is no operation to redo, i.e.
there is no redo step in the undo/redo history, nothing happens.
*/
void redo();
/*! Set the minimum width of the address area.
\param addressWidth Width in characters.
*/
void setAddressWidth(int addressWidth);
/*! Switch the address area on or off.
\param addressArea true (show it), false (hide it).
*/
void setAddressArea(bool addressArea);
/*! Switch the ascii area on or off.
\param asciiArea true (show it), false (hide it).
*/
void setAsciiArea(bool asciiArea);
/*! Switch the highlighting feature on or of.
\param mode true (show it), false (hide it).
*/
void setHighlighting(bool mode);
/*! Undoes the last operation. If there is no operation to undo, i.e.
there is no undo step in the undo/redo history, nothing happens.
*/
void undo();
signals:
/*! Contains the address, where the cursor is located. */
void currentAddressChanged(int address);
/*! Contains the size of the data to edit. */
void currentSizeChanged(int size);
/*! The signal is emited every time, the data is changed. */
void dataChanged();
/*! The signal is emited every time, the overwrite mode is changed. */
void overwriteModeChanged(bool state);
private:
/*! \cond docNever */
QHexEditPrivate *m_qHexEdit_p;
QHBoxLayout *m_Layout;
QScrollArea *m_ScrollArea;
/*! \endcond docNever */
};
#endif

View File

@@ -0,0 +1,882 @@
/*
| ==============================================================================
| Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
| This code may be used in part, or in whole for your application development.
|
|==============================================================================
|
| THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
| NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
| DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
| INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
| OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
| LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| http://code.google.com/p/qhexedit2/
|==============================================================================
*/
#include <QtGui>
#include "QHexEdit_p.h"
#include "Commands.h"
const int HEXCHARS_IN_LINE = 47;
const int GAP_ADR_HEX = 10;
const int GAP_HEX_ASCII = 16;
const int BYTES_PER_LINE = 16;
QHexEditPrivate::QHexEditPrivate(QScrollArea *parent) : QWidget(parent)
{
m_UndoStack = new QUndoStack(this);
m_ScrollArea = parent;
setAddressWidth(4);
setAddressOffset(0);
setAddressArea(true);
setAsciiArea(true);
setHighlighting(true);
setOverwriteMode(true);
setReadOnly(false);
setAddressAreaColor(QColor(0xd4, 0xd4, 0xd4, 0xff));
setHighlightingColor(QColor(0xff, 0xff, 0x99, 0xff));
setSelectionColor(QColor(0x6d, 0x9e, 0xff, 0xff));
setFont(QFont("Courier", 10));
m_Size = 0;
resetSelection(0);
setFocusPolicy(Qt::StrongFocus);
connect(&m_CursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor()));
m_CursorTimer.setInterval(500);
m_CursorTimer.start();
}
void QHexEditPrivate::setAddressOffset(int offset)
{
m_xData.setAddressOffset(offset);
adjust();
}
int QHexEditPrivate::addressOffset()
{
return m_xData.addressOffset();
}
void QHexEditPrivate::setData(const QByteArray &data)
{
m_xData.setData(data);
m_UndoStack->clear();
adjust();
setCursorPos(0);
}
QByteArray QHexEditPrivate::data()
{
return m_xData.data();
}
void QHexEditPrivate::setAddressAreaColor(const QColor &color)
{
m_AddressAreaColor = color;
update();
}
QColor QHexEditPrivate::addressAreaColor()
{
return m_AddressAreaColor;
}
void QHexEditPrivate::setHighlightingColor(const QColor &color)
{
m_HighlightingColor = color;
update();
}
QColor QHexEditPrivate::highlightingColor()
{
return m_HighlightingColor;
}
void QHexEditPrivate::setSelectionColor(const QColor &color)
{
m_SelectionColor = color;
update();
}
QColor QHexEditPrivate::selectionColor()
{
return m_SelectionColor;
}
void QHexEditPrivate::setReadOnly(bool readOnly)
{
m_ReadOnly = readOnly;
}
bool QHexEditPrivate::isReadOnly()
{
return m_ReadOnly;
}
XByteArray & QHexEditPrivate::xData()
{
return m_xData;
}
int QHexEditPrivate::indexOf(const QByteArray & ba, int from)
{
if (from > (m_xData.data().length() - 1))
from = m_xData.data().length() - 1;
int idx = m_xData.data().indexOf(ba, from);
if (idx > -1)
{
int curPos = idx*2;
setCursorPos(curPos + ba.length()*2);
resetSelection(curPos);
setSelection(curPos + ba.length()*2);
ensureVisible();
}
return idx;
}
void QHexEditPrivate::insert(int index, const QByteArray & ba)
{
if (ba.length() > 0)
{
if (m_OverwriteMode)
{
QUndoCommand *arrayCommand= new ArrayCommand(&m_xData, ArrayCommand::replace, index, ba, ba.length());
m_UndoStack->push(arrayCommand);
emit dataChanged();
}
else
{
QUndoCommand *arrayCommand= new ArrayCommand(&m_xData, ArrayCommand::insert, index, ba, ba.length());
m_UndoStack->push(arrayCommand);
emit dataChanged();
}
}
}
void QHexEditPrivate::insert(int index, char ch)
{
QUndoCommand *charCommand = new CharCommand(&m_xData, CharCommand::insert, index, ch);
m_UndoStack->push(charCommand);
emit dataChanged();
}
int QHexEditPrivate::lastIndexOf(const QByteArray & ba, int from)
{
from -= ba.length();
if (from < 0)
from = 0;
int idx = m_xData.data().lastIndexOf(ba, from);
if (idx > -1)
{
int curPos = idx*2;
setCursorPos(curPos);
resetSelection(curPos);
setSelection(curPos + ba.length()*2);
ensureVisible();
}
return idx;
}
void QHexEditPrivate::remove(int index, int len)
{
if (len > 0)
{
if (len == 1)
{
if (m_OverwriteMode)
{
QUndoCommand *charCommand = new CharCommand(&m_xData, CharCommand::replace, index, char(0));
m_UndoStack->push(charCommand);
emit dataChanged();
}
else
{
QUndoCommand *charCommand = new CharCommand(&m_xData, CharCommand::remove, index, char(0));
m_UndoStack->push(charCommand);
emit dataChanged();
}
}
else
{
QByteArray ba = QByteArray(len, char(0));
if (m_OverwriteMode)
{
QUndoCommand *arrayCommand = new ArrayCommand(&m_xData, ArrayCommand::replace, index, ba, ba.length());
m_UndoStack->push(arrayCommand);
emit dataChanged();
}
else
{
QUndoCommand *arrayCommand= new ArrayCommand(&m_xData, ArrayCommand::remove, index, ba, len);
m_UndoStack->push(arrayCommand);
emit dataChanged();
}
}
}
}
void QHexEditPrivate::replace(int index, char ch)
{
QUndoCommand *charCommand = new CharCommand(&m_xData, CharCommand::replace, index, ch);
m_UndoStack->push(charCommand);
resetSelection();
emit dataChanged();
}
void QHexEditPrivate::replace(int index, const QByteArray & ba)
{
QUndoCommand *arrayCommand= new ArrayCommand(&m_xData, ArrayCommand::replace, index, ba, ba.length());
m_UndoStack->push(arrayCommand);
resetSelection();
emit dataChanged();
}
void QHexEditPrivate::replace(int pos, int len, const QByteArray &after)
{
QUndoCommand *arrayCommand= new ArrayCommand(&m_xData, ArrayCommand::replace, pos, after, len);
m_UndoStack->push(arrayCommand);
resetSelection();
emit dataChanged();
}
void QHexEditPrivate::setAddressArea(bool addressArea)
{
m_AddressArea = addressArea;
adjust();
setCursorPos(m_CursorPosition);
}
void QHexEditPrivate::setAddressWidth(int addressWidth)
{
m_xData.setAddressWidth(addressWidth);
setCursorPos(m_CursorPosition);
}
void QHexEditPrivate::setAsciiArea(bool asciiArea)
{
m_AsciiArea = asciiArea;
adjust();
}
void QHexEditPrivate::setFont(const QFont &font)
{
QWidget::setFont(font);
adjust();
}
void QHexEditPrivate::setHighlighting(bool mode)
{
m_Highlighting = mode;
update();
}
void QHexEditPrivate::setOverwriteMode(bool overwriteMode)
{
m_OverwriteMode = overwriteMode;
}
bool QHexEditPrivate::overwriteMode()
{
return m_OverwriteMode;
}
void QHexEditPrivate::redo()
{
m_UndoStack->redo();
emit dataChanged();
setCursorPos(m_CursorPosition);
update();
}
void QHexEditPrivate::undo()
{
m_UndoStack->undo();
emit dataChanged();
setCursorPos(m_CursorPosition);
update();
}
QString QHexEditPrivate::toRedableString()
{
return m_xData.toRedableString();
}
QString QHexEditPrivate::selectionToReadableString()
{
return m_xData.toRedableString(getSelectionBegin(), getSelectionEnd());
}
void QHexEditPrivate::keyPressEvent(QKeyEvent *event)
{
int charX = (m_CursorX - m_xPosHex) / m_CharWidth;
int posX = (charX / 3) * 2 + (charX % 3);
int posBa = (m_CursorY / m_CharHeight) * BYTES_PER_LINE + posX / 2;
/*****************************************************************************/
/* Cursor movements */
/*****************************************************************************/
if (event->matches(QKeySequence::MoveToNextChar))
{
setCursorPos(m_CursorPosition + 1);
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToPreviousChar))
{
setCursorPos(m_CursorPosition - 1);
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToEndOfLine))
{
setCursorPos(m_CursorPosition | (2 * BYTES_PER_LINE -1));
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToStartOfLine))
{
setCursorPos(m_CursorPosition - (m_CursorPosition % (2 * BYTES_PER_LINE)));
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToPreviousLine))
{
setCursorPos(m_CursorPosition - (2 * BYTES_PER_LINE));
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToNextLine))
{
setCursorPos(m_CursorPosition + (2 * BYTES_PER_LINE));
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToNextPage))
{
setCursorPos(m_CursorPosition + (((m_ScrollArea->viewport()->height() / m_CharHeight) - 1) * 2 * BYTES_PER_LINE));
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToPreviousPage))
{
setCursorPos(m_CursorPosition - (((m_ScrollArea->viewport()->height() / m_CharHeight) - 1) * 2 * BYTES_PER_LINE));
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToEndOfDocument))
{
setCursorPos(m_xData.size() * 2);
resetSelection(m_CursorPosition);
}
if (event->matches(QKeySequence::MoveToStartOfDocument))
{
setCursorPos(0);
resetSelection(m_CursorPosition);
}
/*****************************************************************************/
/* Select commands */
/*****************************************************************************/
if (event->matches(QKeySequence::SelectAll))
{
resetSelection(0);
setSelection(2*m_xData.size() + 1);
}
if (event->matches(QKeySequence::SelectNextChar))
{
int pos = m_CursorPosition + 1;
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectPreviousChar))
{
int pos = m_CursorPosition - 1;
setSelection(pos);
setCursorPos(pos);
}
if (event->matches(QKeySequence::SelectEndOfLine))
{
int pos = m_CursorPosition - (m_CursorPosition % (2 * BYTES_PER_LINE)) + (2 * BYTES_PER_LINE);
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectStartOfLine))
{
int pos = m_CursorPosition - (m_CursorPosition % (2 * BYTES_PER_LINE));
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectPreviousLine))
{
int pos = m_CursorPosition - (2 * BYTES_PER_LINE);
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectNextLine))
{
int pos = m_CursorPosition + (2 * BYTES_PER_LINE);
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectNextPage))
{
int pos = m_CursorPosition + (((m_ScrollArea->viewport()->height() / m_CharHeight) - 1) * 2 * BYTES_PER_LINE);
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectPreviousPage))
{
int pos = m_CursorPosition - (((m_ScrollArea->viewport()->height() / m_CharHeight) - 1) * 2 * BYTES_PER_LINE);
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectEndOfDocument))
{
int pos = m_xData.size() * 2;
setCursorPos(pos);
setSelection(pos);
}
if (event->matches(QKeySequence::SelectStartOfDocument))
{
int pos = 0;
setCursorPos(pos);
setSelection(pos);
}
/*****************************************************************************/
/* Edit Commands */
/*****************************************************************************/
if (!m_ReadOnly)
{
/* Hex input */
int key = int(event->text()[0].toAscii());
if ((key>='0' && key<='9') || (key>='a' && key <= 'f'))
{
if (getSelectionBegin() != getSelectionEnd())
{
posBa = getSelectionBegin();
remove(posBa, getSelectionEnd() - posBa);
setCursorPos(2*posBa);
resetSelection(2*posBa);
}
// If insert mode, then insert a byte
if (m_OverwriteMode == false)
if ((charX % 3) == 0)
{
insert(posBa, char(0));
}
// Change content
if (m_xData.size() > 0)
{
QByteArray hexValue = m_xData.data().mid(posBa, 1).toHex();
if ((charX % 3) == 0)
hexValue[0] = key;
else
hexValue[1] = key;
replace(posBa, QByteArray().fromHex(hexValue)[0]);
setCursorPos(m_CursorPosition + 1);
resetSelection(m_CursorPosition);
}
}
/* Cut & Paste */
if (event->matches(QKeySequence::Cut))
{
QString result = QString();
for (int idx = getSelectionBegin(); idx < getSelectionEnd(); idx++)
{
result += m_xData.data().mid(idx, 1).toHex() + " ";
if ((idx % 16) == 15)
result.append("\n");
}
remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin());
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(result);
setCursorPos(getSelectionBegin());
resetSelection(getSelectionBegin());
}
if (event->matches(QKeySequence::Paste))
{
QClipboard *clipboard = QApplication::clipboard();
QByteArray ba = QByteArray().fromHex(clipboard->text().toLatin1());
insert(m_CursorPosition / 2, ba);
setCursorPos(m_CursorPosition + 2 * ba.length());
resetSelection(getSelectionBegin());
}
/* Delete char */
if (event->matches(QKeySequence::Delete))
{
if (getSelectionBegin() != getSelectionEnd())
{
posBa = getSelectionBegin();
remove(posBa, getSelectionEnd() - posBa);
setCursorPos(2*posBa);
resetSelection(2*posBa);
}
else
{
if (m_OverwriteMode)
replace(posBa, char(0));
else
remove(posBa, 1);
}
}
/* Backspace */
if ((event->key() == Qt::Key_Backspace) && (event->modifiers() == Qt::NoModifier))
{
if (getSelectionBegin() != getSelectionEnd())
{
posBa = getSelectionBegin();
remove(posBa, getSelectionEnd() - posBa);
setCursorPos(2*posBa);
resetSelection(2*posBa);
}
else
{
if (posBa > 0)
{
if (m_OverwriteMode)
replace(posBa - 1, char(0));
else
remove(posBa - 1, 1);
setCursorPos(m_CursorPosition - 2);
}
}
}
/* undo */
if (event->matches(QKeySequence::Undo))
{
undo();
}
/* redo */
if (event->matches(QKeySequence::Redo))
{
redo();
}
}
if (event->matches(QKeySequence::Copy))
{
QString result = QString();
for (int idx = getSelectionBegin(); idx < getSelectionEnd(); idx++)
{
result += m_xData.data().mid(idx, 1).toHex() + " ";
if ((idx % 16) == 15)
result.append('\n');
}
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(result);
}
// Switch between insert/overwrite mode
if ((event->key() == Qt::Key_Insert) && (event->modifiers() == Qt::NoModifier))
{
m_OverwriteMode = !m_OverwriteMode;
setCursorPos(m_CursorPosition);
overwriteModeChanged(m_OverwriteMode);
}
ensureVisible();
update();
}
void QHexEditPrivate::mouseMoveEvent(QMouseEvent * event)
{
m_Blink = false;
update();
int actPos = cursorPos(event->pos());
setCursorPos(actPos);
setSelection(actPos);
}
void QHexEditPrivate::mousePressEvent(QMouseEvent * event)
{
m_Blink = false;
update();
int cPos = cursorPos(event->pos());
resetSelection(cPos);
setCursorPos(cPos);
}
void QHexEditPrivate::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
// draw some patterns if needed
painter.fillRect(event->rect(), this->palette().color(QPalette::Base));
if (m_AddressArea)
painter.fillRect(QRect(m_xPosAdr, event->rect().top(), m_xPosHex - GAP_ADR_HEX + 2, height()), m_AddressAreaColor);
if (m_AsciiArea)
{
int linePos = m_xPosAscii - (GAP_HEX_ASCII / 2);
painter.setPen(Qt::gray);
painter.drawLine(linePos, event->rect().top(), linePos, height());
}
painter.setPen(this->palette().color(QPalette::WindowText));
// calc position
int firstLineIdx = ((event->rect().top()/ m_CharHeight) - m_CharHeight) * BYTES_PER_LINE;
if (firstLineIdx < 0)
firstLineIdx = 0;
int lastLineIdx = ((event->rect().bottom() / m_CharHeight) + m_CharHeight) * BYTES_PER_LINE;
if (lastLineIdx > m_xData.size())
lastLineIdx = m_xData.size();
int yPosStart = ((firstLineIdx) / BYTES_PER_LINE) * m_CharHeight + m_CharHeight;
// paint address area
if (m_AddressArea)
{
for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=m_CharHeight)
{
QString address = QString("%1")
.arg(lineIdx + m_xData.addressOffset(), m_xData.realAddressNumbers(), 16, QChar('0'));
painter.drawText(m_xPosAdr, yPos, address);
}
}
// paint hex area
QByteArray hexBa(m_xData.data().mid(firstLineIdx, lastLineIdx - firstLineIdx + 1).toHex());
QBrush highLighted = QBrush(m_HighlightingColor);
QPen colHighlighted = QPen(this->palette().color(QPalette::WindowText));
QBrush selected = QBrush(m_SelectionColor);
QPen colSelected = QPen(Qt::white);
QPen colStandard = QPen(this->palette().color(QPalette::WindowText));
painter.setBackgroundMode(Qt::TransparentMode);
for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=m_CharHeight)
{
QByteArray hex;
int xPos = m_xPosHex;
for (int colIdx = 0; ((lineIdx + colIdx) < m_xData.size() && (colIdx < BYTES_PER_LINE)); colIdx++)
{
int posBa = lineIdx + colIdx;
if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa))
{
painter.setBackground(selected);
painter.setBackgroundMode(Qt::OpaqueMode);
painter.setPen(colSelected);
}
else
{
if (m_Highlighting)
{
// hilight diff bytes
painter.setBackground(highLighted);
if (m_xData.dataChanged(posBa))
{
painter.setPen(colHighlighted);
painter.setBackgroundMode(Qt::OpaqueMode);
}
else
{
painter.setPen(colStandard);
painter.setBackgroundMode(Qt::TransparentMode);
}
}
}
// render hex value
if (colIdx == 0)
{
hex = hexBa.mid((lineIdx - firstLineIdx) * 2, 2);
painter.drawText(xPos, yPos, hex);
xPos += 2 * m_CharWidth;
} else {
hex = hexBa.mid((lineIdx + colIdx - firstLineIdx) * 2, 2).prepend(" ");
painter.drawText(xPos, yPos, hex);
xPos += 3 * m_CharWidth;
}
}
}
painter.setBackgroundMode(Qt::TransparentMode);
painter.setPen(this->palette().color(QPalette::WindowText));
// paint ascii area
if (m_AsciiArea)
{
for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=m_CharHeight)
{
int xPosAscii = m_xPosAscii;
for (int colIdx = 0; ((lineIdx + colIdx) < m_xData.size() && (colIdx < BYTES_PER_LINE)); colIdx++)
{
painter.drawText(xPosAscii, yPos, m_xData.asciiChar(lineIdx + colIdx));
xPosAscii += m_CharWidth;
}
}
}
// paint cursor
if (m_Blink && !m_ReadOnly && hasFocus())
{
if (m_OverwriteMode)
painter.fillRect(m_CursorX, m_CursorY + m_CharHeight - 2, m_CharWidth, 2, this->palette().color(QPalette::WindowText));
else
painter.fillRect(m_CursorX, m_CursorY, 2, m_CharHeight, this->palette().color(QPalette::WindowText));
}
if (m_Size != m_xData.size())
{
m_Size = m_xData.size();
emit currentSizeChanged(m_Size);
}
}
void QHexEditPrivate::setCursorPos(int position)
{
// delete cursor
m_Blink = false;
update();
// cursor in range?
if (m_OverwriteMode)
{
if (position > (m_xData.size() * 2 - 1))
position = m_xData.size() * 2 - 1;
} else {
if (position > (m_xData.size() * 2))
position = m_xData.size() * 2;
}
if (position < 0)
position = 0;
// calc position
m_CursorPosition = position;
m_CursorY = (position / (2 * BYTES_PER_LINE)) * m_CharHeight + 4;
int x = (position % (2 * BYTES_PER_LINE));
m_CursorX = (((x / 2) * 3) + (x % 2)) * m_CharWidth + m_xPosHex;
// immiadately draw cursor
m_Blink = true;
update();
emit currentAddressChanged(m_CursorPosition/2);
}
int QHexEditPrivate::cursorPos(QPoint pos)
{
int result = -1;
// find char under cursor
if ((pos.x() >= m_xPosHex) && (pos.x() < (m_xPosHex + HEXCHARS_IN_LINE * m_CharWidth)))
{
int x = (pos.x() - m_xPosHex) / m_CharWidth;
if ((x % 3) == 0)
x = (x / 3) * 2;
else
x = ((x / 3) * 2) + 1;
int y = ((pos.y() - 3) / m_CharHeight) * 2 * BYTES_PER_LINE;
result = x + y;
}
return result;
}
int QHexEditPrivate::cursorPos()
{
return m_CursorPosition;
}
void QHexEditPrivate::resetSelection()
{
m_SelectionBegin = m_SelectionInit;
m_SelectionEnd = m_SelectionInit;
}
void QHexEditPrivate::resetSelection(int pos)
{
if (pos < 0)
pos = 0;
pos = pos / 2;
m_SelectionInit = pos;
m_SelectionBegin = pos;
m_SelectionEnd = pos;
}
void QHexEditPrivate::setSelection(int pos)
{
if (pos < 0)
pos = 0;
pos = pos / 2;
if (pos >= m_SelectionInit)
{
m_SelectionEnd = pos;
m_SelectionBegin = m_SelectionInit;
}
else
{
m_SelectionBegin = pos;
m_SelectionEnd = m_SelectionInit;
}
}
int QHexEditPrivate::getSelectionBegin()
{
return m_SelectionBegin;
}
int QHexEditPrivate::getSelectionEnd()
{
return m_SelectionEnd;
}
void QHexEditPrivate::updateCursor()
{
if (m_Blink)
m_Blink = false;
else
m_Blink = true;
update(m_CursorX, m_CursorY, m_CharWidth, m_CharHeight);
}
void QHexEditPrivate::adjust()
{
m_CharWidth = fontMetrics().width(QLatin1Char('9'));
m_CharHeight = fontMetrics().height();
m_xPosAdr = 0;
if (m_AddressArea)
m_xPosHex = m_xData.realAddressNumbers()*m_CharWidth + GAP_ADR_HEX;
else
m_xPosHex = 0;
m_xPosAscii = m_xPosHex + HEXCHARS_IN_LINE * m_CharWidth + GAP_HEX_ASCII;
// tell QAbstractScollbar, how big we are
setMinimumHeight(((m_xData.size()/16 + 1) * m_CharHeight) + 5);
if(m_AsciiArea)
setMinimumWidth(m_xPosAscii + (BYTES_PER_LINE * m_CharWidth));
else
setMinimumWidth(m_xPosHex + HEXCHARS_IN_LINE * m_CharWidth);
update();
}
void QHexEditPrivate::ensureVisible()
{
// scrolls to cursorx, cusory (which are set by setCursorPos)
// x-margin is 3 pixels, y-margin is half of charHeight
m_ScrollArea->ensureVisible(m_CursorX, m_CursorY + m_CharHeight/2, 3, m_CharHeight/2 + 2);
}

View File

@@ -0,0 +1,125 @@
#ifndef QHEXEDIT_P_H
#define QHEXEDIT_P_H
/** \cond docNever */
#include <QtGui>
#include "XByteArray.h"
class QHexEditPrivate : public QWidget
{
Q_OBJECT
public:
QHexEditPrivate(QScrollArea *parent);
void setAddressAreaColor(QColor const &color);
QColor addressAreaColor();
void setAddressOffset(int offset);
int addressOffset();
void setCursorPos(int position);
int cursorPos();
void setData(QByteArray const &data);
QByteArray data();
void setHighlightingColor(QColor const &color);
QColor highlightingColor();
void setOverwriteMode(bool overwriteMode);
bool overwriteMode();
void setReadOnly(bool readOnly);
bool isReadOnly();
void setSelectionColor(QColor const &color);
QColor selectionColor();
XByteArray & xData();
int indexOf(const QByteArray & ba, int from = 0);
void insert(int index, const QByteArray & ba);
void insert(int index, char ch);
int lastIndexOf(const QByteArray & ba, int from = 0);
void remove(int index, int len=1);
void replace(int index, char ch);
void replace(int index, const QByteArray & ba);
void replace(int pos, int len, const QByteArray & after);
void setAddressArea(bool addressArea);
void setAddressWidth(int addressWidth);
void setAsciiArea(bool asciiArea);
void setHighlighting(bool mode);
virtual void setFont(const QFont &font);
void undo();
void redo();
QString toRedableString();
QString selectionToReadableString();
signals:
void currentAddressChanged(int address);
void currentSizeChanged(int size);
void dataChanged();
void overwriteModeChanged(bool state);
protected:
void keyPressEvent(QKeyEvent * event);
void mouseMoveEvent(QMouseEvent * event);
void mousePressEvent(QMouseEvent * event);
void paintEvent(QPaintEvent *event);
int cursorPos(QPoint pos); // calc cursorpos from graphics position. DOES NOT STORE POSITION
void resetSelection(int pos); // set selectionStart and selectionEnd to pos
void resetSelection(); // set selectionEnd to selectionStart
void setSelection(int pos); // set min (if below init) or max (if greater init)
int getSelectionBegin();
int getSelectionEnd();
private slots:
void updateCursor();
private:
void adjust();
void ensureVisible();
QColor m_AddressAreaColor;
QColor m_HighlightingColor;
QColor m_SelectionColor;
QScrollArea *m_ScrollArea;
QTimer m_CursorTimer;
QUndoStack *m_UndoStack;
XByteArray m_xData; // has content of Hex Editors
bool m_Blink; // true: then cursor blinks
bool m_RenderingRequired; // Flag to store that rendering is necessary
bool m_AddressArea; // left area of QHexEdit
bool m_AsciiArea; // medium area
bool m_Highlighting; // highlighting of changed bytes
bool m_OverwriteMode;
bool m_ReadOnly; // true: the user can only look and navigate
int m_CharWidth, m_CharHeight; // char dimensions (dpendend on font)
int m_CursorX, m_CursorY; // graphics position of the cursor
int m_CursorPosition; // character positioin in stream (on byte ends in to steps)
int m_xPosAdr, m_xPosHex, m_xPosAscii; // graphics x-position of the areas
int m_SelectionBegin; // First selected char
int m_SelectionEnd; // Last selected char
int m_SelectionInit; // That's, where we pressed the mouse button
int m_Size;
};
/** \endcond docNever */
#endif

View File

@@ -0,0 +1,189 @@
/*
| ==============================================================================
| Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
| This code may be used in part, or in whole for your application development.
|
|==============================================================================
|
| THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
| NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
| DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
| INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
| OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
| LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| http://code.google.com/p/qhexedit2/
|==============================================================================
*/
#include "XByteArray.h"
XByteArray::XByteArray()
{
m_OldSize = -99;
m_AddressNumbers = 4;
m_AddressOffset = 0;
}
int XByteArray::addressOffset()
{
return m_AddressOffset;
}
void XByteArray::setAddressOffset(int offset)
{
m_AddressOffset = offset;
}
int XByteArray::addressWidth()
{
return m_AddressNumbers;
}
void XByteArray::setAddressWidth(int width)
{
if ((width >= 0) && (width<=6))
{
m_AddressNumbers = width;
}
}
QByteArray & XByteArray::data()
{
return m_Data;
}
void XByteArray::setData(QByteArray data)
{
m_Data = data;
m_ChangedData = QByteArray(data.length(), char(0));
}
bool XByteArray::dataChanged(int i)
{
return bool(m_ChangedData[i]);
}
QByteArray XByteArray::dataChanged(int i, int len)
{
return m_ChangedData.mid(i, len);
}
void XByteArray::setDataChanged(int i, bool state)
{
m_ChangedData[i] = char(state);
}
void XByteArray::setDataChanged(int i, const QByteArray & state)
{
int length = state.length();
int len;
if ((i + length) > m_ChangedData.length())
len = m_ChangedData.length() - i;
else
len = length;
m_ChangedData.replace(i, len, state);
}
int XByteArray::realAddressNumbers()
{
if (m_OldSize != m_Data.size())
{
// is addressNumbers wide enought?
QString test = QString("%1")
.arg(m_Data.size() + m_AddressOffset, m_AddressNumbers, 16, QChar('0'));
m_RealAddressNumbers = test.size();
}
return m_RealAddressNumbers;
}
int XByteArray::size()
{
return m_Data.size();
}
QByteArray & XByteArray::insert(int i, char ch)
{
m_Data.insert(i, ch);
m_ChangedData.insert(i, char(1));
return m_Data;
}
QByteArray & XByteArray::insert(int i, const QByteArray & ba)
{
m_Data.insert(i, ba);
m_ChangedData.insert(i, QByteArray(ba.length(), char(1)));
return m_Data;
}
QByteArray & XByteArray::remove(int i, int len)
{
m_Data.remove(i, len);
m_ChangedData.remove(i, len);
return m_Data;
}
QByteArray & XByteArray::replace(int index, char ch)
{
m_Data[index] = ch;
m_ChangedData[index] = char(1);
return m_Data;
}
QByteArray & XByteArray::replace(int index, const QByteArray & ba)
{
int len = ba.length();
return replace(index, len, ba);
}
QByteArray & XByteArray::replace(int index, int length, const QByteArray & ba)
{
int len;
if ((index + length) > m_Data.length())
len = m_Data.length() - index;
else
len = length;
m_Data.replace(index, len, ba.mid(0, len));
m_ChangedData.replace(index, len, QByteArray(len, char(1)));
return m_Data;
}
QChar XByteArray::asciiChar(int index)
{
char ch = m_Data[index];
if ((ch < 0x20) || (ch > 0x7e))
ch = '.';
return QChar(ch);
}
QString XByteArray::toRedableString(int start, int end)
{
int adrWidth = realAddressNumbers();
if (m_AddressNumbers > adrWidth)
adrWidth = m_AddressNumbers;
if (end < 0)
end = m_Data.size();
QString result;
for (int i=start; i < end; i += 16)
{
QString adrStr = QString("%1").arg(m_AddressOffset + i, adrWidth, 16, QChar('0'));
QString hexStr;
QString ascStr;
for (int j=0; j<16; j++)
{
if ((i + j) < m_Data.size())
{
hexStr.append(" ").append(m_Data.mid(i+j, 1).toHex());
ascStr.append(asciiChar(i+j));
}
}
result += adrStr + " " + QString("%1").arg(hexStr, -48) + " " + QString("%1").arg(ascStr, -17) + "\n";
}
return result;
}

View File

@@ -0,0 +1,66 @@
#ifndef XBYTEARRAY_H
#define XBYTEARRAY_H
/** \cond docNever */
#include <QtCore>
/*! XByteArray represents the content of QHexEcit.
XByteArray comprehend the data itself and informations to store if it was
changed. The QHexEdit component uses these informations to perform nice
rendering of the data
XByteArray also provides some functionality to insert, replace and remove
single chars and QByteArras. Additionally some functions support rendering
and converting to readable strings.
*/
class XByteArray
{
public:
explicit XByteArray();
int addressOffset();
void setAddressOffset(int offset);
int addressWidth();
void setAddressWidth(int width);
QByteArray & data();
void setData(QByteArray data);
bool dataChanged(int i);
QByteArray dataChanged(int i, int len);
void setDataChanged(int i, bool state);
void setDataChanged(int i, const QByteArray & state);
int realAddressNumbers();
int size();
QByteArray & insert(int i, char ch);
QByteArray & insert(int i, const QByteArray & ba);
QByteArray & remove(int pos, int len);
QByteArray & replace(int index, char ch);
QByteArray & replace(int index, const QByteArray & ba);
QByteArray & replace(int index, int length, const QByteArray & ba);
QChar asciiChar(int index);
QString toRedableString(int start=0, int end=-1);
signals:
public slots:
private:
QByteArray m_Data;
QByteArray m_ChangedData;
int m_AddressNumbers; // wanted width of address area
int m_AddressOffset; // will be added to the real addres inside bytearray
int m_RealAddressNumbers; // real width of address area (can be greater then wanted width)
int m_OldSize; // size of data
};
/** \endcond docNever */
#endif // XBYTEARRAY_H

View File

@@ -0,0 +1,305 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: Histogram.cpp
Description: populate histogram
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[program/widget] is based in part on the work of
the Qwt project (http://qwt.sf.net).
=============================================================================*/
#include <QLayout>
#include "Histogram.h"
#include "../ExternLib/qwt/qwt_scale_engine.h"
#include "../ExternLib/qwt/qwt_point_data.h"
#include "../ExternLib/qwt/qwt_plot_canvas.h"
class HistogramSource : public QwtSyntheticPointData
{
public:
HistogramSource(const QVector<quint32>& h, int maxValue = 0, int offset = 0)
: QwtSyntheticPointData(h.size(), QwtInterval(0, h.size()-1)),
mMaxValue(maxValue), mOffset(offset)
{
mData = h;
}
virtual QPointF sample( size_t index ) const
{
return QPointF((qreal)x(index), (qreal)y(x(index)));
}
virtual double y(double x) const
{
return mData[(int)x];
}
virtual double x( uint index ) const
{
return (index >= 0 && index < size() ? index : 0);
}
protected:
QVector<quint32> mData;
double mMaxValue; //if zero do not normalize Y to scale of mMaxValue
double mOffset;
};
Histogram::Histogram(const char* name, int maxValueX, QWidget *parent): QwtPlot(parent),
m_Mono(NULL),
m_Red(NULL),
m_Green(NULL),
m_Blue(NULL),
m_MonoCurve(NULL),
m_RedCurve(NULL),
m_GreenCurve(NULL),
m_BlueCurve(NULL),
m_YCurve(NULL),
m_UCurve(NULL),
m_VCurve(NULL),
m_Y(NULL),
m_U(NULL),
m_V(NULL),
m_MaxValueX(maxValueX),
m_MaxValueY(0),
m_dYAxisMaximum(0)
{
setAutoReplot(false);
// panning with the left mouse button
(void) new QwtPlotPanner( canvas() );
// zoom in/out with the wheel
(void) new QwtPlotMagnifier( canvas() );
setAutoFillBackground( true );
setTitle(name);
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// grid
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->enableYMin(true);
grid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine));
grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine));
grid->attach(this);
// axes
//setAxisScale(xBottom, 0.0, mMaxValueX);
//setAxisScale(yLeft, 0.0, 1400000.0);
setAxisAutoScale(xBottom, true);
setAxisAutoScale(yLeft, true);
//// canvas
QwtPlotCanvas *plotCanvas = new QwtPlotCanvas();
plotCanvas->setBorderRadius( 5 );
plotCanvas->setLineWidth(1);
plotCanvas->setFrameStyle(QFrame::Box | QFrame::Plain );
setCanvas(plotCanvas);
QPalette canvasPalette( Qt::white );
canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
canvas()->setPalette( canvasPalette );
// Insert new curves
QPen penMono(Qt::black);
penMono.setWidth(2);
m_MonoCurve = new QwtPlotCurve(tr("mono"));
m_MonoCurve->setStyle(QwtPlotCurve::Lines);
//m_MonoCurve->setBrush(Qt::black);
m_MonoCurve->setPen(penMono);
m_MonoCurve->setYAxis(QwtPlot::yLeft);
m_MonoCurve->attach(this);
QPen penRed(Qt::red);
penRed.setWidth(2);
m_RedCurve = new QwtPlotCurve(tr("red"));
//m_RedCurve->setBrush(Qt::red);
m_RedCurve->setStyle(QwtPlotCurve::Lines);
m_RedCurve->setPen(penRed);
m_RedCurve->setYAxis(QwtPlot::yLeft);
m_RedCurve->attach(this);
QPen penGreen(Qt::green);
penGreen.setWidth(2);
m_GreenCurve = new QwtPlotCurve(tr("green"));
//m_GreenCurve->setBrush(Qt::green);
m_GreenCurve->setStyle(QwtPlotCurve::Lines);
m_GreenCurve->setPen(penGreen);
m_GreenCurve->setYAxis(QwtPlot::yLeft);
m_GreenCurve->attach(this);
QPen penBlue(Qt::blue);
penBlue.setWidth(2);
m_BlueCurve = new QwtPlotCurve(tr("blue"));
//m_BlueCurve->setBrush(Qt::blue);
m_BlueCurve->setStyle(QwtPlotCurve::Lines);
m_BlueCurve->setPen(penBlue);
m_BlueCurve->setYAxis(QwtPlot::yLeft);
m_BlueCurve->attach(this);
QPen penYellow(Qt::darkYellow);
penYellow.setWidth(2);
m_YCurve = new QwtPlotCurve(tr("Y"));
//m_YCurve->setBrush(Qt::darkYellow);
m_YCurve->setStyle(QwtPlotCurve::Lines);
m_YCurve->setPen(penYellow);
m_YCurve->setYAxis(QwtPlot::yLeft);
m_YCurve->attach(this);
QPen penCyan(Qt::darkCyan);
penCyan.setWidth(2);
m_UCurve = new QwtPlotCurve(tr("U"));
//m_UCurve->setBrush(Qt::darkCyan);
m_UCurve->setStyle(QwtPlotCurve::Lines);
m_UCurve->setPen(penCyan);
m_UCurve->setYAxis(QwtPlot::yLeft);
m_UCurve->attach(this);
QPen penMagenta(Qt::darkMagenta);
penMagenta.setWidth(2);
m_VCurve = new QwtPlotCurve(tr("V"));
//m_VCurve->setBrush(Qt::darkMagenta);
m_VCurve->setStyle(QwtPlotCurve::Lines);
m_VCurve->setPen(penMagenta);
m_VCurve->setYAxis(QwtPlot::yLeft);
m_VCurve->attach(this);
// picker
m_PlotPicker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas());
m_PlotPicker->setStateMachine(new QwtPickerDragPointMachine());
m_PlotPicker->setRubberBandPen(QColor( 128, 0, 0 ));
m_PlotPicker->setRubberBand(QwtPicker::CrossRubberBand);
m_PlotPicker->setTrackerPen(QColor( 128, 0, 0 ));
setAutoReplot(true);
}
Histogram::~Histogram()
{
}
void Histogram::resizeEvent(QResizeEvent *event)
{
QwtPlot::resizeEvent( event );
}
void Histogram::populate( const QVector<quint32> &histogramData, const QString &sColorComponent )
{
const bool doReplot = autoReplot();
setAutoReplot(false);
if( 0 == sColorComponent.compare("M") )
{
m_Mono = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_MonoCurve->setData(m_Mono);
}
if( 0 == sColorComponent.compare("R") )
{
m_Red = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_RedCurve->setData(m_Red);
}
if( 0 == sColorComponent.compare("G") )
{
m_Green = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_GreenCurve->setData(m_Green);
}
if( 0 == sColorComponent.compare("B") )
{
m_Blue = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_BlueCurve->setData(m_Blue);
}
if( 0 == sColorComponent.compare("Y") )
{
m_Y = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_YCurve->setData(m_Y);
}
if( 0 == sColorComponent.compare("U") )
{
m_U = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_UCurve->setData(m_U);
}
if( 0 == sColorComponent.compare("V") )
{
m_V = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
m_VCurve->setData(m_V);
}
setAutoReplot(doReplot);
replot();
}
void Histogram::setHistogramTitle ( const QString &sTitle )
{
setTitle (sTitle);
}
void Histogram::setLeftAxisY ( const double &dMaximum )
{
//reset pen
QPen penBlack(Qt::black);
penBlack.setWidth(1);
m_MonoCurve->setPen(penBlack);
m_RedCurve->setPen(penBlack);
m_GreenCurve->setPen(penBlack);
m_BlueCurve->setPen(penBlack);
setAxisScale(yLeft, 0.0, dMaximum );
m_dYAxisMaximum = dMaximum;
}
void Histogram::setBottomAxisX ( const double &dMaximum )
{
//set pen to default
QPen penBlack(Qt::black);
penBlack.setWidth(2);
m_MonoCurve->setPen(penBlack);
QPen penRed(Qt::red);
penRed.setWidth(2);
m_RedCurve->setPen(penRed);
QPen penGreen(Qt::green);
penGreen.setWidth(2);
m_GreenCurve->setPen(penGreen);
QPen penBlue(Qt::blue);
penBlue.setWidth(2);
m_BlueCurve->setPen(penBlue);
setAxisScale(xBottom, 0.0, dMaximum );
}

View File

@@ -0,0 +1,94 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: Histogram.cpp
Description: populate histogram
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[program/widget] is based in part on the work of
the Qwt project (http://qwt.sf.net).
=============================================================================*/
#ifndef HISTOGRAM_H
#define HISTOGRAM_H
#include "../ExternLib/qwt/qwt_plot.h"
#include "../ExternLib/qwt/qwt_plot_curve.h"
#include "../ExternLib/qwt/qwt_plot_marker.h"
#include "../ExternLib/qwt/qwt_plot_picker.h"
#include "../ExternLib/qwt/qwt_plot_renderer.h"
#include "../ExternLib/qwt/qwt_plot_grid.h"
#include "../ExternLib/qwt/qwt_plot_picker.h"
#include "../ExternLib/qwt/qwt_legend.h"
#include "../ExternLib/qwt/qwt_plot_panner.h"
#include "../ExternLib/qwt/qwt_plot_magnifier.h"
#include "../ExternLib/qwt/qwt_picker_machine.h"
#include "../ExternLib/qwt/qwt_slider.h"
class HistogramSource;
class Histogram : public QwtPlot
{
public:
explicit Histogram(const char* name, int maxValue, QWidget *parent = 0);
~Histogram();
void populate ( const QVector<quint32> &histogramData, const QString &sColorComponent );
void setHistogramTitle ( const QString &sTitle );
void setLeftAxisY ( const double &dMaximum );
void setBottomAxisX ( const double &dMaximum );
protected:
virtual void resizeEvent( QResizeEvent * );
private:
HistogramSource *m_Mono;
HistogramSource *m_Red;
HistogramSource *m_Green;
HistogramSource *m_Blue;
HistogramSource *m_Y;
HistogramSource *m_U;
HistogramSource *m_V;
QwtPlotCurve *m_MonoCurve;
QwtPlotCurve *m_RedCurve;
QwtPlotCurve *m_GreenCurve;
QwtPlotCurve *m_BlueCurve;
QwtPlotCurve *m_YCurve;
QwtPlotCurve *m_UCurve;
QwtPlotCurve *m_VCurve;
QwtPlotPicker *m_PlotPicker;
quint32 m_MaxValueX;
quint32 m_MaxValueY;
double m_dYAxisMaximum;
signals:
public slots:
};
#endif // HISTOGRAM_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HistogramThread.h
Description: a worker thread to process histogram data
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef HISTOGRAMTHREAD_H
#define HISTOGRAMTHREAD_H
#include <QTime>
#include <QThread>
#include <QVector>
#include <QMutex>
#include <QMutexLocker>
#include <qwaitcondition.h>
#include "Helper.h"
#include <VimbaCPP/Include/IFrameObserver.h>
#include <VimbaCPP/Include/Frame.h>
#include <VimbaCPP/Include/Camera.h>
class HistogramThread : public QThread
{
Q_OBJECT
typedef QSharedPointer<unsigned char> data_storage;
public:
private:
template<typename T>
struct statistics
{
typedef T value_type;
T Min;
T Max;
T Mean;
};
ConsumerQueue<tFrameInfo> m_FrameInfo;
QMutex m_Lock;
bool m_Stopping;
public:
HistogramThread ( );
~HistogramThread ( void );
void stopProcessing();
void setThreadFrame ( const tFrameInfo &info );
protected:
virtual void run();
void histogramMono8 ( const tFrameInfo &info );
void histogramRGB8 ( const tFrameInfo &info );
void histogramBGR8 ( const tFrameInfo &info );
void histogramYUV411 ( const tFrameInfo &info );
void histogramYUV422 ( const tFrameInfo &info );
void histogramYUV444 ( const tFrameInfo &info );
void histogramNotSupportedYet ( const tFrameInfo &info );
void histogramBayerRG12Packed ( const tFrameInfo &info );
void histogramBayerRG8 ( const tFrameInfo &info );
void histogramBayerRG12 ( const tFrameInfo &info );
private:
template<typename T>
statistics<T> calcWeightedMean( const QVector<VmbUint32_t>& rValues );
signals:
void histogramDataFromThread ( const QVector<QVector <quint32> > &histData,
const QString &sHistogramTitle,
const double &nMaxHeight_YAxis,
const double &nMaxWidth_XAxis,
const QVector <QStringList> &statistics);
};
#endif

View File

@@ -0,0 +1,365 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HistogramWindow.cpp
Description: Histogram Window
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[program/widget] is based in part on the work of
the Qwt project (http://qwt.sf.net).
=============================================================================*/
#include "HistogramWindow.h"
#include "Histogram.h"
HistogramWindow::HistogramWindow(QWidget *parent) :
QWidget(parent), m_Histogram ( NULL ), m_StatisticsTable ( NULL ), m_nXAxisMax ( 0 )
{
m_DataLayout = new QGridLayout();
QHBoxLayout *layoutHorizontal = new QHBoxLayout();
m_DataLayout->addLayout(layoutHorizontal,0,0);
setLayout(m_DataLayout);
QIcon printIcon;
printIcon.addFile( QString::fromUtf8(":/VimbaViewer/Images/print.png"), QSize(), QIcon::Normal, QIcon::Off);
m_PrintButton = new QToolButton( this );
m_PrintButton->setIcon(printIcon);
m_PrintButton->setIconSize(QSize(32,32));
m_PrintButton->setToolTip(tr("Print the histogram"));
m_PrintButton->setCursor(Qt::PointingHandCursor);
m_PrintButton->setStyleSheet(QString::fromUtf8("QToolButton{background-color: rgb(128, 0, 0);} QToolTip {}"));
layoutHorizontal->addWidget(m_PrintButton);
QIcon pdfIcon;
pdfIcon.addFile( QString::fromUtf8(":/VimbaViewer/Images/pdf.png"), QSize(), QIcon::Normal, QIcon::Off);
m_ExportButton = new QToolButton( this );
m_ExportButton->setIcon(pdfIcon);
m_ExportButton->setIconSize(QSize(32,32));
m_ExportButton->setToolTip(tr("Export the histogram to PDF"));
m_ExportButton->setCursor(Qt::PointingHandCursor);
m_ExportButton->setStyleSheet(QString::fromUtf8("QToolButton{background-color: rgb(128, 0, 0);} QToolTip {}"));
layoutHorizontal->addWidget(m_ExportButton);
QObject::connect( m_PrintButton, SIGNAL(clicked()), this, SLOT(onPrint()));
QObject::connect( m_ExportButton, SIGNAL(clicked()), this, SLOT(onExport()));
}
HistogramWindow::~HistogramWindow( )
{
if( NULL != m_Histogram)
{
delete m_Histogram;
m_Histogram = NULL;
}
}
void HistogramWindow::initializeStatistic ( void )
{
m_StatisticsTable = new QTableWidget();
m_DataLayout->addWidget(m_StatisticsTable);
m_StatisticsTable->setColumnCount(4);
QStringList sHeader;
sHeader << "" << tr("Minimum") << tr("Maximum") << tr("Mean");
m_StatisticsTable->setHorizontalHeaderLabels(sHeader);
m_StatisticsTable->setFixedHeight(135);
m_StatisticsTable->verticalHeader()->setVisible(false);
}
void HistogramWindow::deinitializeStatistic ( void )
{
if(0 != m_StatisticsTable)
{
delete m_StatisticsTable;
m_StatisticsTable = NULL;
}
}
void HistogramWindow::setStatistic ( const QStringList component,
const QStringList minimum,
const QStringList maximum,
const QStringList average,
const QString sFormat )
{
m_StatisticsTable->clearContents();
m_StatisticsTable->setRowCount(component.size());
for(int i=0; i < component.size(); i++) /* component */
{
QTableWidgetItem *item = new QTableWidgetItem();
item->setText(component.at(i));
/* Mono 8 */
if(1 == component.size())
{
item->setBackgroundColor(Qt::black);
item->setForeground(QBrush(QColor(255,255,255)));
}
/* RGB, YUV */
if(3 == component.size())
{
if (0 == sFormat.compare("RGB")|| sFormat.contains("Bayer"))
{
switch(i)
{
case 0:
item->setBackgroundColor(Qt::red);
break;
case 1:
item->setBackgroundColor(Qt::green);
break;
case 2:
item->setForeground(QBrush(QColor(255,255,255)));
item->setBackgroundColor(Qt::blue);
break;
default:
break;
}
}
if(0 == sFormat.compare("YUV"))
{
switch(i)
{
case 0:
item->setBackgroundColor(Qt::darkYellow);
break;
case 1:
item->setBackgroundColor(Qt::darkCyan);
break;
case 2:
//item->setForeground(QBrush(QColor(255,255,255)));
item->setBackgroundColor(Qt::darkMagenta);
break;
default:
break;
}
}
}
m_StatisticsTable->setItem(i, 0, item);
}
for(int j=0; j < minimum.size(); j++) /* minimum */
{
QTableWidgetItem *item = new QTableWidgetItem();
item->setText(minimum.at(j));
m_StatisticsTable->setItem(j, 1, item);
}
for(int k=0; k < maximum.size(); k++) /* maximum */
{
QTableWidgetItem *item = new QTableWidgetItem();
item->setText(maximum.at(k));
m_StatisticsTable->setItem(k, 2, item);
}
for(int l=0; l < average.size(); l++) /* average */
{
QTableWidgetItem *item = new QTableWidgetItem();
item->setText(average.at(l));
m_StatisticsTable->setItem(l, 3, item);
}
}
void HistogramWindow::createGraphWidgets ( void )
{
m_Histogram = new Histogram(" ", 255, this); //255: Default
m_DataLayout->addWidget(m_Histogram, 2, 0);
m_AutoScaleYAxis = new QCheckBox();
m_AutoScaleYAxis->setText(tr("Auto scale Y-AXIS ON"));
m_AutoScaleYAxis->setChecked(true);
m_DataLayout->addWidget(m_AutoScaleYAxis);
connect( m_AutoScaleYAxis, SIGNAL(clicked(bool)), this, SLOT(onAutoScaleYAxisClick(bool)) );
m_Histogram->installEventFilter(this);
}
void HistogramWindow::onAutoScaleYAxisClick ( bool bValue )
{
if(bValue)
{
m_Histogram->setAxisAutoScale(0, true);
m_Histogram->setAxisAutoScale(2, true);
m_Histogram->setAxisScale(2, 0.0, m_nXAxisMax );
}
else
{
m_Histogram->setAxisAutoScale(0, false);
m_Histogram->setAxisAutoScale(2, false);
}
}
void HistogramWindow::updateHistogram( const QVector<QVector<quint32> > &histogramData, const QString &sNewHistogramTitle,
const double &nMaxHeight_YAxis, const double &nMaxWidth_XAxis )
{
if( 0 != m_sCurrentHistogramTitle.compare(sNewHistogramTitle) )
{
m_Histogram->setHistogramTitle( sNewHistogramTitle );
//m_Histogram->setLeftAxisY(nMaxHeight_YAxis);
if(m_sCurrentHistogramTitle.contains("Mono"))
{
QVector <quint32> resetValues(255, 0);
m_Histogram->populate(resetValues, "M");
}
if(m_sCurrentHistogramTitle.contains("8"))
{
QVector <quint32> resetValues(255, 0);
m_Histogram->populate(resetValues, "R"); // Red
m_Histogram->populate(resetValues, "G"); // Green
m_Histogram->populate(resetValues, "B"); // Blue
}
if( m_sCurrentHistogramTitle.contains("BayerRG12"))
{
QVector <quint32> resetValues(4095, 0);
m_Histogram->populate(resetValues, "R"); // Red
m_Histogram->populate(resetValues, "G"); // Green
m_Histogram->populate(resetValues, "B"); // Blue
}
if(m_sCurrentHistogramTitle.contains("YUV"))
{
QVector <quint32> resetValues(255, 0);
m_Histogram->populate(resetValues, "Y"); // Y
m_Histogram->populate(resetValues, "U"); // U
m_Histogram->populate(resetValues, "V"); // V
}
m_Histogram->setBottomAxisX(nMaxWidth_XAxis);
m_nXAxisMax = nMaxWidth_XAxis;
m_sCurrentHistogramTitle = sNewHistogramTitle;
}
if( 1 == histogramData.size() && (m_sCurrentHistogramTitle.contains("Mono"))) // 1 color component -> Mono
m_Histogram->populate(histogramData.at(0), "M");
if( 3 == histogramData.size() && m_sCurrentHistogramTitle.contains("RGB8") ||
3 == histogramData.size() && m_sCurrentHistogramTitle.contains("BGR8") ||
m_sCurrentHistogramTitle.contains("Bayer") ) // 3 color components -> R,G,B
{
m_Histogram->populate(histogramData.at(0), "R"); // Red
m_Histogram->populate(histogramData.at(1), "G"); // Green
m_Histogram->populate(histogramData.at(2), "B"); // Blue
}
if( 3 == histogramData.size() && m_sCurrentHistogramTitle.contains("YUV") ) // 3 color components -> Y,U,V
{
m_Histogram->populate(histogramData.at(0), "Y"); // Y
m_Histogram->populate(histogramData.at(1), "U"); // U
m_Histogram->populate(histogramData.at(2), "V"); // V
}
/*if( m_sCurrentHistogramTitle.contains("Not Supported Yet") )
m_Histogram->populate(histogramData.at(0), "M");*/
}
void HistogramWindow::onPrint ( void )
{
#ifndef QT_NO_PRINTER
QPrinter printer( QPrinter::HighResolution );
QString docName = m_Histogram->title().text();
if ( !docName.isEmpty() )
{
docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) );
printer.setDocName ( docName );
}
printer.setCreator( "Histogram" );
printer.setOrientation( QPrinter::Landscape );
QPrintDialog dialog( &printer );
if ( dialog.exec() )
{
QwtPlotRenderer renderer;
if ( printer.colorMode() == QPrinter::GrayScale )
{
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
}
renderer.renderTo( m_Histogram, printer );
}
#endif
}
void HistogramWindow::onExport ( void )
{
#ifndef QT_NO_PRINTER
QString fileName = "Histogram.pdf";
#else
QString fileName = "Histogram.png";
#endif
#ifndef QT_NO_FILEDIALOG
const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();
QStringList filter;
filter += "PDF Documents (*.pdf)";
#ifndef QWT_NO_SVG
filter += "SVG Documents (*.svg)";
#endif
filter += "Postscript Documents (*.ps)";
if ( imageFormats.size() > 0 )
{
QString imageFilter( "Images (" );
for ( int i = 0; i < imageFormats.size(); i++ )
{
if ( i > 0 )
imageFilter += " ";
imageFilter += "*.";
imageFilter += imageFormats[i];
}
imageFilter += ")";
filter += imageFilter;
}
fileName = QFileDialog::getSaveFileName( this, "Export File Name", fileName,
filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
#endif
if ( !fileName.isEmpty() )
{
QwtPlotRenderer renderer;
renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, false );
renderer.renderDocument( m_Histogram, fileName, QSizeF( 300, 200 ), 85 );
}
}
bool HistogramWindow::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::Wheel)
{
m_AutoScaleYAxis->setChecked(false);
}
return false;
}

View File

@@ -0,0 +1,84 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: HistogramWindow.h
Description: Histogram Window
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[program/widget] is based in part on the work of
the Qwt project (http://qwt.sf.net).
=============================================================================*/
#ifndef HISTOGRAMWINDOW_H
#define HISTOGRAMWINDOW_H
#include <QWidget>
#include <QGridLayout>
#include <QToolButton>
#include <QImageWriter>
#include <QFileDialog>
#include <QPrinter>
#include <QPrintDialog>
#include <QTableWidget>
#include <QHeaderView>
#include <QEvent>
#include <QCheckBox>
class Histogram;
class HistogramWindow : public QWidget
{
Q_OBJECT
public:
explicit HistogramWindow(QWidget *parent = 0);
~HistogramWindow();
void createGraphWidgets ( void );
void initializeStatistic ( void );
void deinitializeStatistic ( void );
void setStatistic ( const QStringList component, const QStringList minimum, const QStringList maximum, const QStringList average, const QString sFormat );
private:
QToolButton *m_PrintButton;
QToolButton *m_ExportButton;
QGridLayout *m_DataLayout;
Histogram *m_Histogram;
QString m_sCurrentHistogramTitle;
QTableWidget *m_StatisticsTable;
QCheckBox *m_AutoScaleYAxis;
unsigned int m_nXAxisMax;
bool eventFilter (QObject *object, QEvent *event);
signals:
private slots:
void onPrint ( void );
void onExport ( void );
public slots:
void updateHistogram( const QVector<QVector<quint32> > &histogramData, const QString &sNewHistogramTitle,
const double &nMaxHeight_YAxis, const double &nMaxWidth_XAxis );
void onAutoScaleYAxisClick ( bool bValue );
};
#endif // HISTOGRAMWINDOW_H

View File

@@ -0,0 +1,79 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: IntSpinBox.cpp
Description: Spinbox to handle integer feature
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "IntSpinBox.h"
IntSpinBox::IntSpinBox ( QWidget *parent ): QSpinBox ( parent )
{
}
IntSpinBox::~IntSpinBox ( void )
{
}
/*nMax = nMax - (nMax % nInc);
nMax = nMax - ((nMax-nMin) % nInc);
*/
void IntSpinBox::stepBy( int steps )
{
int nInterval = singleStep();
int nValue = value();
if(0 < steps ) //stepUp
{
{
if( maximum() >= (nValue+nInterval))
{
setValue( nValue+nInterval);
}
}
}
else //stepDown
{
if( 0 != (nValue-nInterval) % nInterval )
{
/* value % ninterval should be 0 */
nValue -= ( (nValue-nInterval) + (nInterval - ((nValue-nInterval) % nInterval)) );
if( minimum() <= nValue)
{
setValue( nValue);
}
}
else
{
setValue( nValue-nInterval);
}
}
editingFinished();
}

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: IntSpinBox.h
Description: Spinbox to handle integer feature
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef INTSPINBOX_H
#define INTSPINBOX_H
#include <QSpinBox>
class IntSpinBox : public QSpinBox
{
Q_OBJECT
public:
protected:
private:
public:
IntSpinBox ( QWidget *parent );
~IntSpinBox ( void );
protected:
private:
virtual void stepBy ( int steps );
};
#endif

View File

@@ -0,0 +1,102 @@
/*=============================================================================
Copyright (C) 2012 - 2013 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: LineEditCompleter.cpp
Description: LineEdit implementation used by Filter
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "LineEditCompleter.h"
LineEditCompleter::LineEditCompleter(QWidget *parent) : QLineEdit(parent), c(0)
{
}
LineEditCompleter::~LineEditCompleter()
{
}
void LineEditCompleter::setCompleter(MultiCompleter *completer)
{
if (c)
QObject::disconnect(c, 0, this, 0);
c = completer;
if (!c)
return;
c->setWidget(this);
connect(completer, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&)));
}
MultiCompleter *LineEditCompleter::completer() const
{
return c;
}
void LineEditCompleter::insertCompletion(const QString& completion)
{
setText(completion);
}
void LineEditCompleter::keyPressEvent(QKeyEvent *e)
{
if (c && c->popup()->isVisible())
{
/* The following keys are forwarded by the completer to the widget */
switch (e->key())
{
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Escape:
case Qt::Key_Tab:
case Qt::Key_Backtab:
e->ignore();
return; /* Let the completer do default behavior */
}
}
bool isShortcut = (e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E;
if (!isShortcut)
QLineEdit::keyPressEvent(e); /* Don't send the shortcut (CTRL-E) to the text edit. */
if (!c)
return;
bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
if (!isShortcut && !ctrlOrShift && e->modifiers() != Qt::NoModifier)
{
c->popup()->hide();
return;
}
c->update(text());
c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
if( Qt::Key_Enter == e->key())
{
c->popup()->hide();
}
}

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (C) 2012 - 2013 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: LineEditCompleter.h
Description: LineEdit used by Filter
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef LINEEDITCOMPLETER_H
#define LINEEDITCOMPLETER_H
#include <QLineEdit>
#include "MultiCompleter.h"
#include <QKeyEvent>
class LineEditCompleter : public QLineEdit
{
Q_OBJECT
public:
LineEditCompleter(QWidget *parent = 0);
~LineEditCompleter();
void setCompleter(MultiCompleter *c);
MultiCompleter *completer() const;
protected:
void keyPressEvent(QKeyEvent *e);
private slots:
void insertCompletion(const QString &completion);
private:
MultiCompleter *c;
};
#endif

View File

@@ -0,0 +1,82 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: LoggerWindow.cpp
Description: Logging widget used by the MainWindow only.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "LoggerWindow.h"
#include <QTime>
#include <QPainter>
LoggerWindow::LoggerWindow ( QWidget *parent ): QListWidget ( parent )
{
}
LoggerWindow::~LoggerWindow ( void )
{
}
void LoggerWindow::logging ( const QString &sInfo, const VimbaViewerLogCategory &logCategory )
{
QIcon icon;
QListWidgetItem *item = new QListWidgetItem(QTime::currentTime().toString("hh:mm:ss.zzz")+" "+ sInfo);
switch(logCategory)
{
case VimbaViewerLogCategory_OK:
icon.addFile(QString::fromUtf8(":/VimbaViewer/Images/okay.png"), QSize(), QIcon::Normal, QIcon::Off);
break;
case VimbaViewerLogCategory_WARNING:
icon.addFile(QString::fromUtf8(":/VimbaViewer/Images/warning.png"), QSize(), QIcon::Normal, QIcon::Off);
break;
case VimbaViewerLogCategory_ERROR:
icon.addFile( QString::fromUtf8(":/VimbaViewer/Images/error.png"), QSize(), QIcon::Normal, QIcon::Off);
break;
case VimbaViewerLogCategory_INFO:
icon.addFile( QString::fromUtf8(":/VimbaViewer/Images/info.png"), QSize(), QIcon::Normal, QIcon::Off);
break;
default: break;
}
item->setIcon(icon);
this->addItem(item);
this->scrollToBottom();
}
void LoggerWindow::plainLogging ( const QString &sInfo )
{
QListWidgetItem *item = new QListWidgetItem(" "+sInfo);
this->addItem(new QListWidgetItem(""));
this->addItem(item);
this->scrollToBottom();
}

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: LoggerWindow.h
Description: Logging widget used by the MainWindow only.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef LOGGERWINDOW_H
#define LOGGERWINDOW_H
#include <QListWidget>
#include "Helper.h"
class LoggerWindow : public QListWidget
{
Q_OBJECT
public:
protected:
private:
public:
LoggerWindow ( QWidget *parent );
~LoggerWindow ( void );
void logging( const QString &sInfo , const VimbaViewerLogCategory &logCategory );
void plainLogging ( const QString &sInfo );
protected:
private:
};
#endif

View File

@@ -0,0 +1,296 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: MainInformationWindow.cpp
Description: Main MDI Window for logging and event viewer
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "MainInformationWindow.h"
#include <QToolBar>
MainInformationWindow::MainInformationWindow ( QWidget *parent , Qt::WindowFlags flags, CameraPtr pCam ) : QMainWindow( parent, flags ),
m_WindowMenu( NULL ), m_OpenLoggerAct( NULL ), m_OpenEventViewerAct( NULL ), m_CloseAllAct( NULL ), m_TileAct( NULL ),
m_CascadeAct( NULL ), m_MDIArea( NULL ) , m_nEventViewerPosition (-1) , m_bIsLogging ( false ), m_bIsEventViewerOpen ( false ),
m_NumberOfLogging ( 0 )
{
m_pCam = pCam;
/* make sure to treat this as a widget :) */
this->setWindowFlags(Qt::Widget);
QToolBar* toolBarInformation = new QToolBar(this);
toolBarInformation->setObjectName(QString::fromUtf8("toolBarInformation"));
toolBarInformation->setWindowTitle("Information ToolBar");
toolBarInformation->setStyleSheet(QString::fromUtf8("QToolBar{background-color: transparent;} QToolTip {""}"));
this->addToolBar(toolBarInformation);
/* create MDI area */
m_MDIArea = new QMdiArea;
setCentralWidget(m_MDIArea);
createAction();
toolBarInformation->addAction(m_OpenLoggerAct);
toolBarInformation->addAction(m_OpenEventViewerAct);
toolBarInformation->addSeparator();
toolBarInformation->addAction(m_CascadeAct);
toolBarInformation->addAction(m_TileAct);
toolBarInformation->addAction(m_CloseAllAct);
m_OpenLoggerAct->setCheckable(true);
m_OpenEventViewerAct->setCheckable(true);
createMenu();
connect(m_MDIArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(updateMenus()));
updateMenus();
}
MainInformationWindow::~MainInformationWindow ( )
{
}
void MainInformationWindow::createAction ( void )
{
m_OpenLoggerAct = new QAction(QIcon(":/VimbaViewer/Images/logger.png"), tr("&Open logging window"), this );
m_OpenEventViewerAct = new QAction(QIcon(":/VimbaViewer/Images/open_eventviewer.png"), tr("&Open event viewer"), this );
m_CascadeAct = new QAction(QIcon(":/VimbaViewer/Images/cascade.png"),tr("&Cascade"), this);
m_TileAct = new QAction(QIcon(":/VimbaViewer/Images/tile.png"),tr("&Tile "), this);
m_CloseAllAct = new QAction(QIcon(":/VimbaViewer/Images/close.png"),tr("&Close all"), this);
m_OpenLoggerAct->setPriority(QAction::LowPriority);
m_OpenEventViewerAct->setPriority(QAction::LowPriority);
m_CascadeAct->setPriority(QAction::LowPriority);
m_TileAct->setPriority(QAction::LowPriority);
m_CloseAllAct->setPriority(QAction::LowPriority);
connect(m_OpenLoggerAct, SIGNAL(triggered()), this, SLOT(openLogger()));
connect(m_OpenEventViewerAct, SIGNAL(triggered()), this, SLOT(openEventViewer()));
connect(m_CloseAllAct, SIGNAL(triggered()), m_MDIArea, SLOT(closeAllSubWindows()));
connect(m_CascadeAct, SIGNAL(triggered()), m_MDIArea, SLOT(cascadeSubWindows()));
connect(m_TileAct, SIGNAL(triggered()), m_MDIArea, SLOT(tileSubWindows()));
}
void MainInformationWindow::createMenu ( void )
{
m_WindowMenu = menuBar()->addMenu(tr("&Window"));
m_WindowMenu->addAction(m_OpenLoggerAct);
m_WindowMenu->addAction(m_OpenEventViewerAct);
m_WindowMenu->addSeparator();
m_WindowMenu->addAction(m_TileAct);
m_WindowMenu->addAction(m_CascadeAct);
m_WindowMenu->addSeparator();
m_WindowMenu->addAction(m_CloseAllAct);
}
void MainInformationWindow::feedLogger ( const QString &sWhatWindow, const QString &sInfo, const VimbaViewerLogCategory &logCategory )
{
QStringList sInfoList;
sInfoList << sInfo;
for(int i=0; i< m_MDIChildList.size(); i++)
{
if( 0 == m_MDIChildList.at(i)->getName().compare(sWhatWindow) )
m_MDIChildList.at(i)->setLogger(sInfoList, logCategory);
}
}
void MainInformationWindow::openLoggingWindow ( void )
{
m_OpenLoggerAct->setChecked(true);
openLogger();
}
void MainInformationWindow::openLogger ( void )
{
createMdiChild("Logging");
/* getting info from the camera */
std::string sInfo;
if(VmbErrorSuccess == m_pCam->GetName(sInfo))
feedLogger("Logging", QString("Name: "+ QString::fromStdString(sInfo)), VimbaViewerLogCategory_INFO);
sInfo.clear();
if(VmbErrorSuccess == m_pCam->GetModel(sInfo))
feedLogger("Logging", QString("Model: "+ QString::fromStdString(sInfo)), VimbaViewerLogCategory_INFO);
sInfo.clear();
if(VmbErrorSuccess == m_pCam->GetSerialNumber(sInfo))
feedLogger("Logging", QString("S/N: "+ QString::fromStdString(sInfo)), VimbaViewerLogCategory_INFO);
sInfo.clear();
if(VmbErrorSuccess == m_pCam->GetID(sInfo))
feedLogger("Logging", QString("ID: "+ QString::fromStdString(sInfo)), VimbaViewerLogCategory_INFO);
sInfo.clear();
if(VmbErrorSuccess == m_pCam->GetInterfaceID(sInfo))
feedLogger("Logging", QString("Interface ID: "+ QString::fromStdString(sInfo)), VimbaViewerLogCategory_INFO);
}
void MainInformationWindow::openEventViewer ( void )
{
createMdiChild("Event Viewer");
}
void MainInformationWindow::onDestroyed ( QObject *obj )
{
QString s = obj->objectName();
if(0 == s.compare("Logging"))
{
m_OpenLoggerAct->setChecked(false);
}
if(0 == s.compare("Event Viewer"))
{
m_bIsLogging = false;
m_OpenEventViewerAct->setChecked(false);
}
/* just make sure to clean it up */
for(int i=0; i< m_MDIChildList.size(); i++)
{
if( 0 == m_MDIChildList.at(i)->getName().compare(s) )
{
if(0 == s.compare("Event Viewer"))
{
/* make sure to stop logging before delete the object */
m_bIsLogging = false;
m_MDIChildList.at(i)->stopLogger();
}
m_MDIChildList.removeAt(i);
updateEventViewerPosition();
}
}
}
void MainInformationWindow::updateEventViewerPosition ( void )
{
for(int i=0; i< m_MDIChildList.size(); i++)
{
if( 0 == m_MDIChildList.at(i)->getName().compare("Event Viewer"))
{
m_nEventViewerPosition = i;
m_bIsEventViewerOpen = true;
return;
}
}
m_bIsEventViewerOpen = false;
}
void MainInformationWindow::updateMenus ( void )
{
bool bHasMdiChild = (0 != activeMdiChild());
m_CascadeAct->setEnabled(bHasMdiChild);
m_TileAct->setEnabled(bHasMdiChild);
m_CloseAllAct->setEnabled(bHasMdiChild);
}
MdiChild *MainInformationWindow::activeMdiChild()
{
if (QMdiSubWindow *activeSubWindow = m_MDIArea->activeSubWindow())
return qobject_cast<MdiChild *>(activeSubWindow->widget());
return 0;
}
void MainInformationWindow::createMdiChild ( const QString &sWhatWindow )
{
if(!m_MDIChildList.isEmpty())
{
for(int i=0; i< m_MDIChildList.size(); i++)
{
if(m_bIsLogging)
m_bIsLogging = false;
/* window is already available */
if( 0 == m_MDIChildList.at(i)->getName().compare(sWhatWindow))
{
/* close and delete it */
QMdiSubWindow *activeSubWindow = NULL;
/* make sure that the window to close is active */
do
{
m_MDIArea->activateNextSubWindow();
activeSubWindow = m_MDIArea->activeSubWindow();
} while ( 0 != activeSubWindow->windowTitle().compare(sWhatWindow) );
if(0 == sWhatWindow.compare("Event Viewer"))
{
/* make sure to stop logging before delete the object */
m_bIsLogging = false;
m_MDIChildList.at(i)->stopLogger();
}
m_MDIArea->removeSubWindow(activeSubWindow);
disconnect(m_MDIChildList.at(i), SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
m_MDIChildList.removeAt(i);
updateEventViewerPosition();
m_bIsLogging = true;
return ;
}
}
}
m_MDIChildList.append(new MdiChild(sWhatWindow));
if( 0 == sWhatWindow.compare("Logging") )
{
m_MDIArea->addSubWindow(m_MDIChildList.back())->setWindowIcon(QIcon(":/VimbaViewer/Images/logger.png"));
m_MDIChildList.back()->setObjectName("Logging");
m_MDIChildList.back()->showMaximized();
}
else if( 0 == sWhatWindow.compare("Event Viewer") )
{
m_MDIArea->addSubWindow(m_MDIChildList.back())->setWindowIcon(QIcon(":/VimbaViewer/Images/open_eventviewer.png"));
m_MDIChildList.back()->setObjectName("Event Viewer");
m_MDIChildList.back()->showMaximized();
}
updateEventViewerPosition();
m_bIsLogging = true;
connect(m_MDIChildList.back(), SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
m_MDIChildList.back()->show();
}
void MainInformationWindow::setEventMessage ( const QStringList &sMessage )
{
if( (m_bIsEventViewerOpen) && (m_bIsLogging) )
{
if ( ! m_MDIChildList.at(m_nEventViewerPosition)->getPauseState() )
{
/* show the last 100 rows */
if ( MAX_LOGGING == ++m_NumberOfLogging )
{
m_NumberOfLogging = 0;
m_MDIChildList.at(m_nEventViewerPosition)->clearLogger();
}
m_MDIChildList.at(m_nEventViewerPosition)->setLogger(sMessage, VimbaViewerLogCategory_INFO);
}
}
}

View File

@@ -0,0 +1,93 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: MainInformationWindow.h
Description: Main MDI Window for logging and event viewer
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef MAININFORMATIONWINDOW_H
#define MAININFORMATIONWINDOW_H
#include <QMainWindow>
#include <QAction>
#include <QMenuBar>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <VimbaCPP/Include/VimbaSystem.h>
#include "MdiChild.h"
const unsigned int MAX_LOGGING = 100;
using AVT::VmbAPI::CameraPtr;
class MdiChild;
class MainInformationWindow : public QMainWindow
{
Q_OBJECT
public:
protected:
private:
QAction *m_OpenLoggerAct;
QAction *m_OpenEventViewerAct;
QAction *m_CloseAllAct;
QAction *m_TileAct;
QAction *m_CascadeAct;
QMenu *m_WindowMenu;
QMdiArea *m_MDIArea;
QList< MdiChild *> m_MDIChildList;
CameraPtr m_pCam;
int m_nEventViewerPosition;
bool m_bIsLogging;
bool m_bIsEventViewerOpen;
unsigned int m_NumberOfLogging;
public:
MainInformationWindow ( QWidget *parent = 0, Qt::WindowFlags flags = 0, CameraPtr pCam = CameraPtr() );
~MainInformationWindow ( void );
void setEventMessage ( const QStringList &sMessage );
void openLoggingWindow ( void );
void feedLogger ( const QString &sWhatWindow, const QString &sInfo, const VimbaViewerLogCategory &logCategory );
protected:
private:
void createAction ( void );
void createMenu ( void );
MdiChild *activeMdiChild ( void );
void createMdiChild ( const QString &sWhatWindow );
void updateEventViewerPosition ( void );
private slots:
void openLogger ( void );
void openEventViewer ( void );
void updateMenus ( void );
void onDestroyed ( QObject *obj );
};
#endif

View File

@@ -0,0 +1,174 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: MdiChild.cpp
Description: MDI Widget for logging and event viewer
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <QtGui>
#include "MdiChild.h"
MdiChild::MdiChild(QString sTitle) : m_bIsPause (false)
{
m_sName = sTitle;
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(sTitle);
QVBoxLayout *verticalLayout_Parent = new QVBoxLayout(this);
verticalLayout_Parent->setObjectName("verticalLayout_Parent");
QVBoxLayout *verticalLayout_Child = new QVBoxLayout();
verticalLayout_Child->setObjectName("verticalLayout_Child");
m_Logger = new QTextEdit(this);
m_Logger->setObjectName("m_Logger");
m_Logger->setReadOnly(true);
m_Logger->setLineWrapMode(QTextEdit::NoWrap);
m_Logger->setStyleSheet(QString::fromUtf8("background-color: rgb(0, 0, 0);\n" "color: rgb(255, 255, 255);"));
verticalLayout_Child->addWidget(m_Logger);
verticalLayout_Parent->addLayout(verticalLayout_Child);
/* if its an Event Viewer window, then add these two buttons on widget */
if(0 == sTitle.compare("Event Viewer"))
{
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
m_StartStopBtn = new QPushButton(this);
m_StartStopBtn->setObjectName(QString::fromUtf8("m_StartStopBtn"));
horizontalLayout->addWidget(m_StartStopBtn);
m_ClearBtn = new QPushButton(this);
m_ClearBtn->setObjectName(QString::fromUtf8("m_ClearBtn"));
horizontalLayout->addWidget(m_ClearBtn);
m_StartStopBtn->setText("Pause");
m_ClearBtn->setText("Clear");
QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addItem(horizontalSpacer);
verticalLayout_Parent->addLayout(horizontalLayout);
connect(m_ClearBtn, SIGNAL(clicked()), this, SLOT(onClearLogger()));
connect(m_StartStopBtn, SIGNAL(clicked()), this, SLOT(onPauseLogger()));
}
}
MdiChild::~MdiChild()
{
}
void MdiChild::onClearLogger ( )
{
m_Logger->clear();
}
void MdiChild::onPauseLogger ( )
{
if(!m_bIsPause)
{
m_bIsPause = true;
m_StartStopBtn->setText("Resume");
}
else
{
m_bIsPause = false;
m_StartStopBtn->setText("Pause");
}
}
bool MdiChild::getPauseState ( void )
{
return m_bIsPause;
}
void MdiChild::setLogger ( const QStringList &sInfo, const VimbaViewerLogCategory &logCategory )
{
if(!m_bIsPause)
{
if(VimbaViewerLogCategory_INFO == logCategory)
{
m_Logger->append(sInfo.join("\n"));
QTextCursor c = m_Logger->textCursor();
c.movePosition(QTextCursor::End);
m_Logger->setTextCursor(c);
return;
}
}
QString sInformation = "<br>" + sInfo.at(0);
QString sErrorHtml = "<font color=\"Red\">";
QString sOKHtml = "<font color=\"lime\">";
QString sWarningHtml = "<font color=\"Yellow\">";
QString sInfoHtml = "<font color=\"White\">";
QString sEndHtml = "</font>";
QTextCursor cursorText = m_Logger->textCursor();
if(!m_bIsPause)
{
switch(logCategory)
{
case VimbaViewerLogCategory_OK:
sInformation = sOKHtml % sInformation;
break;
case VimbaViewerLogCategory_WARNING:
sInformation = sWarningHtml % sInformation;
break;
case VimbaViewerLogCategory_ERROR:
sInformation = sErrorHtml % sInformation;
break;
default:
sInformation = sInfoHtml % sInformation;
break;
}
sInformation = sInformation % sEndHtml;
m_Logger->insertHtml(sInformation);
cursorText.movePosition(QTextCursor::End);
m_Logger->setTextCursor(cursorText);
}
}
void MdiChild::stopLogger( void )
{
m_bIsPause = true;
}
void MdiChild::clearLogger( void )
{
onClearLogger ();
}
QString MdiChild::getName( void )
{
return m_sName;
}

View File

@@ -0,0 +1,71 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: MdiChild.h
Description: MDI Widget for logging and event viewer
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef MDICHILD_H
#define MDICHILD_H
#include <QWidget>
#include <QTextEdit>
#include <QPushButton>
#include "Helper.h"
class MdiChild : public QWidget
{
Q_OBJECT
public:
protected:
private:
QString m_sName;
QTextEdit *m_Logger;
QPushButton *m_StartStopBtn;
QPushButton *m_ClearBtn;
bool m_bIsPause;
public:
MdiChild(QString sTitle);
~MdiChild();
QString getName ( void );
void setLogger ( const QStringList &sInfo, const VimbaViewerLogCategory &logCategory );
void stopLogger ( void );
void clearLogger ( void );
bool getPauseState ( void );
protected:
private:
private slots:
void onClearLogger ( void );
void onPauseLogger ( void );
};
#endif

View File

@@ -0,0 +1,53 @@
/*=============================================================================
Copyright (C) 2012 - 2013 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: MultiCompleter.h
Description: QCompleter with multi selection
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "MultiCompleter.h"
MultiCompleter::MultiCompleter ( const QStringList& items, QObject* parent )
: QCompleter( items, parent ), m_list(items), m_model()
{
setModel(&m_model);
}
MultiCompleter::~MultiCompleter()
{
}
QString MultiCompleter::pathFromIndex ( const QModelIndex& index ) const
{
QString path = QCompleter::pathFromIndex( index );
QString text = static_cast<QLineEdit*>( widget() )->text();
int pos = text.lastIndexOf( '|' );
if ( pos >= 0 )
path = text.left( pos ) + "|" + path;
return path;
}

View File

@@ -0,0 +1,75 @@
/*=============================================================================
Copyright (C) 2012 - 2013 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: MultiCompleter.h
Description: QCompleter with multi selection
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef MULTICOMPLETER_H
#define MULTICOMPLETER_H
#include <QCompleter>
#include <QStringList>
#include <QLineEdit>
#include <QModelIndex>
#include <QStringListModel>
class MultiCompleter : public QCompleter
{
Q_OBJECT
private:
QStringList m_list;
QStringListModel m_model;
QString m_word;
public:
MultiCompleter( const QStringList& items, QObject* parent );
~MultiCompleter();
inline void update(QString word)
{
/* Do any filtering you like */
int pos = word.lastIndexOf( '|' ) + 1;
while ( pos < word.length() && word.at( pos ) == QLatin1Char( ' ' ) )
pos++;
word = word.mid( pos ) ;
/* Include all items that contain word */
QStringList filtered = m_list.filter(word, caseSensitivity());
m_model.setStringList(filtered);
m_word = word;
complete();
}
inline QString word()
{
return m_word;
}
public:
QString pathFromIndex( const QModelIndex& index ) const;
};
#endif

View File

@@ -0,0 +1,60 @@
/*=============================================================================
Copyright (C) 2012 - 2013 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: SortFilterProxyModel.cpp
Description: Filter pattern proxy
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "SortFilterProxyModel.h"
SortFilterProxyModel::SortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
{
// get source-model index for current row
QModelIndex source_index = sourceModel()->index(source_row, this->filterKeyColumn(), source_parent) ;
if(source_index.isValid())
{
// if any of children matches the filter, then current index matches the filter as well
int nCount = sourceModel()->rowCount(source_index) ;
for(int i=0; i<nCount; ++i)
{
if(filterAcceptsRow(i, source_index))
{
return true ;
}
}
// check current index itself :
QString key = sourceModel()->data(source_index, filterRole()).toString();
return key.contains(filterRegExp()) ;
}
// parent call for initial behaviour
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) ;
}

View File

@@ -0,0 +1,44 @@
/*=============================================================================
Copyright (C) 2012 - 2013 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: SortFilterProxyModel.h
Description: Filter pattern proxy
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef SORTFILTERPROXYMODEL_H
#define SORTFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
class SortFilterProxyModel : public QSortFilterProxyModel
{
public:
SortFilterProxyModel(QObject *parent = 0);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
private:
};
#endif

View File

@@ -0,0 +1,13 @@
#ifndef TAB_EXTENSION_RESULT_H_
#define TAB_EXTENSION_RESULT_H_
/*Results that will be returned from plugin functions*/
enum TabExtensionResult
{
TER_OK = 0,
TER_RuntimeError ,
TER_OutOfMemory ,
TER_OutOfRange ,
TER_NotSupported ,
TER_BadParameter ,
};
#endif

View File

@@ -0,0 +1,269 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: Viewer.cpp
Description: - Displaying data from the camera in RGB32 format.
- Scrolling, Rotating, Saving single image
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <UI/Viewer.h>
#include <QMenu>
#include <QMouseEvent>
#include <QFileDialog>
#include <QScrollBar>
Viewer::Viewer ( QWidget *parent ): QGraphicsView ( parent ), m_ZoomFactor ( 0 ), m_ColorInterpolationAct ( NULL ),
m_bColorInterpolationState ( true ), m_bIsFitToWindow ( false ),
m_bIsPressed ( false )
{
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setMouseTracking(true);
}
Viewer::~Viewer ( void )
{
}
void Viewer::enableFitToWindow ( const bool &bIsEnable )
{
m_bIsFitToWindow = bIsEnable;
}
void Viewer::setDefaultSize ( void )
{
resetCachedContent();
resetMatrix();
resetTransform();
m_ZoomFactor = 0;
}
void Viewer::SetCenter ( const QPointF& centerPoint )
{
/* Get the rectangle of the visible area in scene coords */
QRectF visibleArea = mapToScene(rect()).boundingRect();
/* Get the scene area */
QRectF sceneBounds = sceneRect();
double boundX = visibleArea.width() / 2.0;
double boundY = visibleArea.height() / 2.0;
double boundWidth = sceneBounds.width() - 2.0 * boundX;
double boundHeight = sceneBounds.height() - 2.0 * boundY;
/* The max boundary that the centerPoint can be to */
QRectF bounds(boundX, boundY, boundWidth, boundHeight);
if(bounds.contains(centerPoint))
{
/* We are within the bounds */
m_CurrentCenterPoint = centerPoint;
}
else
{
/* We need to clamp or use the center of the screen */
if(visibleArea.contains(sceneBounds))
{
/* Use the center of scene ie. we can see the whole scene */
m_CurrentCenterPoint = sceneBounds.center();
}
else
{
m_CurrentCenterPoint = centerPoint;
/* We need to clamp the center. The centerPoint is too large */
if(centerPoint.x() > bounds.x() + bounds.width())
{
m_CurrentCenterPoint.setX(bounds.x() + bounds.width());
}
else if(centerPoint.x() < bounds.x())
{
m_CurrentCenterPoint.setX(bounds.x());
}
if(centerPoint.y() > bounds.y() + bounds.height())
{
m_CurrentCenterPoint.setY(bounds.y() + bounds.height());
}
else if(centerPoint.y() < bounds.y())
{
m_CurrentCenterPoint.setY(bounds.y());
}
}
}
/* Update the scrollbars */
centerOn(m_CurrentCenterPoint);
}
void Viewer::saveImage ( void )
{
emit savingImage();
}
void Viewer::colorInterpolationChecked ( bool bState )
{
m_bColorInterpolationState = bState;
emit setColorInterpolationState (m_bColorInterpolationState);
}
void Viewer::updateInterpolationState ( const bool &bState )
{
m_bColorInterpolationState = bState;
}
/* Handles when the mouse button is pressed */
void Viewer::mousePressEvent ( QMouseEvent* event )
{
m_bIsPressed = true;
Qt::MouseButton mouseBtn = event->button();
if( Qt::RightButton == mouseBtn )
{
QMenu menu;
menu.addAction(QIcon(":/VimbaViewer/Images/save.png"), tr("Save Image..."), this, SLOT(saveImage()));
if(NULL != m_ColorInterpolationAct)
{
disconnect(m_ColorInterpolationAct, SIGNAL(toggled(bool)), this, SLOT(colorInterpolationChecked(bool)) );
delete m_ColorInterpolationAct;
m_ColorInterpolationAct = NULL;
}
m_ColorInterpolationAct = new QAction(this);
m_ColorInterpolationAct->setObjectName(QString::fromUtf8("ColorInterpolation"));
m_ColorInterpolationAct->setCheckable(true);
m_ColorInterpolationAct->setText("Color Interpolation");
m_ColorInterpolationAct->setChecked(m_bColorInterpolationState);
menu.addAction(m_ColorInterpolationAct);
connect(m_ColorInterpolationAct, SIGNAL(toggled(bool)), this, SLOT(colorInterpolationChecked(bool)) );
menu.exec(event->globalPos());
}
else
{
/* For panning the view */
m_LastPanPoint = event->pos();
if(horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible())
setCursor(Qt::ClosedHandCursor);
else if((!horizontalScrollBar()->isVisible() && !verticalScrollBar()->isVisible()))
setCursor(Qt::ArrowCursor);
}
}
/* Handles when the mouse button is released */
void Viewer::mouseReleaseEvent ( QMouseEvent* event )
{
m_bIsPressed = false;
if(horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible())
setCursor(Qt::OpenHandCursor);
m_LastPanPoint = QPoint();
}
/* Handles the mouse move event */
void Viewer::mouseMoveEvent ( QMouseEvent* event )
{
if((horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible()) && !m_bIsPressed)
setCursor(Qt::OpenHandCursor);
else if((!horizontalScrollBar()->isVisible() && !verticalScrollBar()->isVisible()))
setCursor(Qt::ArrowCursor);
if(!m_LastPanPoint.isNull())
{
/* Get how much we panned */
QPointF delta = mapToScene(m_LastPanPoint) - mapToScene(event->pos());
m_LastPanPoint = event->pos();
/* Update the center e.g do the pan */
QPointF F = GetCenter();
SetCenter(GetCenter() + delta);
}
}
/* Zoom the view in and out. */
void Viewer::wheelEvent ( QWheelEvent* event )
{
0 < event->delta() ? zoomIn() : zoomOut();
}
/**
* Need to update the center so there is no jolt in the
* interaction after resizing the widget.
*/
void Viewer::resizeEvent ( QResizeEvent* event )
{
/* Call the subclass resize so the scrollbars are updated correctly */
if(m_bIsFitToWindow)
{
fitInView(scene()->itemsBoundingRect(), Qt::IgnoreAspectRatio);
}
QGraphicsView::resizeEvent(event);
}
QPointF Viewer::GetCenter ( void )
{
return m_CurrentCenterPoint;
}
void Viewer::zoomIn ( void )
{
/* Get the position of the mouse before scaling, in scene coords */
QPointF pointBeforeScale(mapToScene(pos()));
/* Get the original screen center point */
QPointF screenCenter = GetCenter();
/* How fast we zoom */
double scaleFactor = 1.15;
scale(scaleFactor, scaleFactor);
m_ZoomFactor++;
updateCenter(pointBeforeScale, screenCenter);
}
void Viewer::zoomOut ( void )
{
/* Get the position of the mouse before scaling, in scene coords */
QPointF pointBeforeScale(mapToScene(pos()));
/* Get the original screen center point */
QPointF screenCenter = GetCenter();
/* How fast we zoom */
double scaleFactor = 1.15;
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
m_ZoomFactor--;
updateCenter(pointBeforeScale, screenCenter);
}
void Viewer::updateCenter ( QPointF pointBeforeScale, QPointF screenCenter )
{
/* Get the position after scaling, in scene coords */
QPointF pointAfterScale(mapToScene(pos()));
/* Get the offset of how the screen moved */
QPointF offset = pointBeforeScale - pointAfterScale;
/* Adjust to the new center for correct zooming */
QPointF newCenter = screenCenter + offset;
SetCenter(newCenter);
}

View File

@@ -0,0 +1,95 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: Viewer.h
Description: - Displaying data from the camera in RGB32 format.
- Scrolling, Rotating, Saving single image
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef VIEWER_H
#define VIEWER_H
#include <QGraphicsView>
#include <QGraphicsTextItem>
#include <QtCore/QTextStream>
#include "Helper.h"
class Viewer : public QGraphicsView
{
Q_OBJECT
public:
QAction *m_ColorInterpolationAct;
protected:
private:
QGraphicsScene *m_Scene;
QGraphicsView *m_View;
double m_ZoomFactor;
bool m_bColorInterpolationState;
bool m_bIsFitToWindow;
bool m_bIsPressed;
public:
Viewer ( QWidget *parent = NULL);
~Viewer ( void );
void enableFitToWindow ( const bool &bIsEnable );
void setDefaultSize ( void );
void updateInterpolationState ( const bool &bState );
void zoomIn ( void ) ;
void zoomOut ( void ) ;
protected:
QPointF m_CurrentCenterPoint;
/* From panning the view */
QPoint m_LastPanPoint;
/* Set the current center point in the */
void SetCenter ( const QPointF& centerPoint );
QPointF GetCenter ( void );
void updateCenter ( QPointF pointBeforeScale, QPointF screenCenter );
/* Take over the interaction */
virtual void mousePressEvent ( QMouseEvent* event );
virtual void mouseReleaseEvent ( QMouseEvent* event );
virtual void mouseMoveEvent ( QMouseEvent* event );
virtual void wheelEvent ( QWheelEvent* event );
virtual void resizeEvent ( QResizeEvent* event);
private:
private slots:
void saveImage ( void );
void colorInterpolationChecked ( bool bState );
signals:
void savingImage ( void );
void setColorInterpolationState ( const bool &bState);
};
#endif

View File

@@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef TAB_EXTENSIONINTERFACE_H
#define TAB_EXTENSIONINTERFACE_H
#include <QString>
#include <VimbaCPP/Include/VimbaSystem.h>
#include "TabExtensionResult.h"
typedef QSharedPointer<QVector<AVT::VmbAPI::FeaturePtr> > QFeatureVectorPtr;
/*Tab Extension Interface*/
class TabExtensionInterface : public QObject
{
public:
virtual ~TabExtensionInterface() {}
virtual TabExtensionResult get(const QSharedPointer<QVector<AVT::VmbAPI::FeaturePtr> > &qFeatVec, QWidget &widget, QMap<QString, QVariant> *parameters = NULL) = 0;
virtual bool connectToResetFps(QObject* pReceiver, const char* pszSlot) = 0;
virtual bool connectFromAcquire(QObject* pSender, const char* pszSignal) = 0;
};
Q_DECLARE_INTERFACE(TabExtensionInterface,
"com.trolltech.Plugin.TabExtensionInterface/1.0");
#endif