Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include<iostream>
- #include<sstream>
- #include<QtCore/QMimeData>
- #include<QtCore/QObject>
- #include<QtCore/QDebug>
- #include<QtGui/QMoveEvent>
- #include<QtGui/QPainter>
- #include<QtGui/QBitmap>
- #include<QtGui/QColor>
- #include<QtGui/QImage>
- #include<QtWidgets/QApplication>
- #include<QtWidgets/QMainWindow>
- #include<QtWidgets/QPushButton>
- #include<QtWidgets/QStatusBar>
- #include<QtWidgets/QGroupBox>
- #include<QtWidgets/QLabel>
- using namespace std;
- namespace{
- void MsgBox( const std::string msg, const std::string caption = "result" ){
- MessageBox( NULL, msg.c_str(), caption.c_str(), MB_OK );
- return;
- }
- void MsgBox( const std::wstring msg, const std::wstring caption = L"result" ){
- MessageBoxW( NULL, msg.c_str(), caption.c_str(), MB_OK );
- return;
- }
- }
- // utf-8 で保存しないと意味ないらしい...
- #pragma execution_character_set("utf-8")
- /* -+-+-+-+- Mainにも公開するもの -+-+-+-+- */
- namespace QtUse{
- namespace LocaleSet{
- enum LOCALNUMBERS{
- Japanese = 1,
- English = 2,
- Spanish = 3,
- French = 4,
- Russian = 5,
- Latin = 6,
- Chinese = 7,
- Italian = 8,
- Unknown = 100
- };
- }
- namespace QtRrc{
- class ICursor{
- public:
- virtual ~ICursor(){}
- virtual bool fromFile( const std::string filepath ) = 0;
- virtual QCursor cur( void ) = 0;
- virtual bool empty( void ) = 0;
- };
- class IIcon{
- public:
- virtual ~IIcon(){}
- virtual bool fromFile( const std::string filepath ) = 0;
- virtual QIcon ico( void ) = 0;
- virtual bool empty( void ) = 0;
- };
- class IImage{
- public:
- virtual ~IImage(){}
- virtual bool fromFile( const std::string filepath ) = 0;
- virtual QImage img( void ) = 0;
- virtual int height( void ) = 0;
- virtual int width( void ) = 0;
- virtual bool empty( void ) = 0;
- };
- }
- namespace QtEvent{
- class IWindowEvent{
- public:
- protected:
- private:
- };
- class IMainWindowEvent : public IWindowEvent{
- public:
- protected:
- private:
- };
- }
- namespace QtWindow{
- class IWindow{
- public:
- virtual ~IWindow(){}
- virtual QWidget* widget( void ) const = 0;
- virtual HWND hWnd( void ) const = 0;
- virtual int id( void ) const = 0;
- virtual void setFont( LOGFONT lf ) = 0;
- virtual LOGFONT font( void ) const = 0;
- virtual void setCursor( QtUse::QtRrc::ICursor* cursor ) = 0;
- // virtual cursor( void )
- virtual void setAcceptDrops( bool state ) = 0;
- virtual bool acceptDrops( void ) const = 0;
- virtual void setLocale( int nLocale ) = 0;
- virtual int locale( void ) const = 0;
- virtual void setToolTip( const std::string msg ) = 0;
- virtual std::string toolTip( void ) const = 0;
- virtual void setColor( COLORREF foreColor, COLORREF bgColor ) = 0;
- virtual void show( void ) = 0;
- virtual void hide( void ) = 0;
- virtual void move( int x, int y ) = 0;
- virtual int x( void ) const = 0;
- virtual int y( void ) const = 0;
- virtual void resize( int height, int width ) = 0;
- virtual int height( void ) const = 0;
- virtual int width( void ) const = 0;
- virtual void setVisible( bool state ) = 0;
- virtual bool visible( void ) const = 0;
- virtual void setEnabled( bool state ) = 0;
- virtual bool isEnabled( void ) const = 0;
- virtual void setFocus( void ) = 0;
- virtual bool focus( void ) const = 0;
- virtual void setText( const std::string text ) = 0;
- virtual std::string getText( void ) const = 0;
- };
- class IMainWindow : public IWindow{
- public:
- virtual ~IMainWindow(){}
- virtual void setIcon( QtUse::QtRrc::IIcon* icon ) = 0;
- virtual int addEvent( QtUse::QtEvent::IMainWindowEvent* event ) = 0;
- };
- }
- namespace QtWorker{
- class IApplication{
- public:
- virtual ~IApplication(){}
- virtual void setIcon( QtUse::QtRrc::IIcon* icon ) = 0;
- virtual int exec( void ) = 0;
- };
- class IPainter{
- public:
- virtual ~IPainter(){}
- virtual bool begin( QtUse::QtWindow::IWindow* window ) = 0;
- virtual bool end( void ) = 0;
- virtual bool show( int x, int y, int height, int width, QtUse::QtRrc::IImage* image ) = 0;
- };
- }
- }
- /* -+-+-+-+- DLLのヘッダ -+-+-+-+- */
- namespace Crack{
- QString StringToQstring( const std::string str );
- std::string QstringToString( const QString &qstr );
- std::wstring QstringToWstring( const QString &qstr );
- QLocale::Language LocalesetToQlocalelanguage( int nLocale );
- int QlocalelanguageToLocaleset( QLocale::Language lang );
- QString ColorrefToQstringCss( QString objectName, COLORREF fore, COLORREF back );
- QCursor CreateQcursor( const std::string filepath );
- QIcon CreateQicon( const std::string filepath );
- QFont LogfontToQfont( LOGFONT *lf );
- LOGFONT QfontToLogfont( QFont* f );
- QString CreateBorderCss( QString objectName, bool state );
- QString CreateObjectName( const std::string TypeName, int id );
- int CalcIdFromObjectName( const QString objectName );
- }
- namespace QtRrcConcrete{
- class CCursor : public QtUse::QtRrc::ICursor{
- public:
- CCursor( int id );
- ~CCursor();
- bool fromFile( const std::string filepath );
- QCursor cur( void );
- bool empty( void );
- private:
- QCursor cur_;
- int id_;
- };
- }
- namespace QtRrcConcrete{
- class CIcon : public QtUse::QtRrc::IIcon{
- public:
- CIcon( int id );
- ~CIcon();
- bool fromFile( const std::string filepath );
- QIcon ico( void );
- bool empty( void );
- private:
- QIcon ico_;
- int id_;
- };
- }
- namespace QtRrcConcrete{
- class CImage : public QtUse::QtRrc::IImage{
- public:
- CImage( int id );
- ~CImage();
- bool fromFile( const std::string filepath );
- QImage img( void );
- int height( void );
- int width( void );
- bool empty( void );
- private:
- QImage img_;
- int id_;
- };
- }
- namespace QtWorkerConcrete{
- class CApplication : public QtUse::QtWorker::IApplication{
- public:
- CApplication( int argc, char *argv[] );
- ~CApplication();
- void setIcon( QtUse::QtRrc::IIcon* icon );
- int exec( void );
- private:
- QApplication* app;
- };
- }
- namespace QtWorkerConcrete{
- class CPainter : public QtUse::QtWorker::IPainter{
- public:
- CPainter();
- ~CPainter();
- bool begin( QtUse::QtWindow::IWindow* window );
- bool end( void );
- bool show( int x, int y, int height, int width, QtUse::QtRrc::IImage* image );
- private:
- QPainter painter;
- };
- }
- namespace QtWindowConcrete{
- class WMainWindow : public QMainWindow, public QtUse::QtWindow::IMainWindow{
- public:
- WMainWindow( QWidget* parent, int id );
- ~WMainWindow();
- QWidget* widget( void ) const;
- HWND hWnd( void ) const;
- int id( void ) const;
- void setFont( LOGFONT lf );
- LOGFONT font( void ) const;
- void setCursor( QtUse::QtRrc::ICursor* cursor );
- // cursor( void );
- void setAcceptDrops( bool state );
- bool acceptDrops( void ) const;
- void setLocale( int nLocale );
- int locale( void ) const;
- void setToolTip( const std::string msg );
- std::string toolTip( void ) const;
- void setColor( COLORREF foreColor, COLORREF bgColor );
- void show( void );
- void hide( void );
- void move( int x, int y );
- int x( void ) const;
- int y( void ) const;
- void resize( int height, int width );
- int height( void ) const;
- int width( void ) const;
- void setVisible( bool state );
- bool visible( void ) const;
- void setEnabled( bool state );
- bool isEnabled( void ) const;
- void setFocus( void );
- bool focus( void ) const;
- void setText( const std::string text );
- std::string getText( void ) const;
- void setIcon( QtUse::QtRrc::IIcon* icon );
- int addEvent( QtUse::QtEvent::IMainWindowEvent* event );
- protected:
- private:
- int id_;
- QtUse::QtEvent::IMainWindowEvent* event_;
- };
- }
- namespace Factories{
- // リソース系
- QtUse::QtRrc::ICursor* CreateCursorInstance( int id );
- QtUse::QtRrc::IIcon* CreateIconInstance( int id );
- QtUse::QtRrc::IImage* CreateImageInstance( int id );
- // ワーカ系
- QtUse::QtWorker::IApplication* CreateApplicationInstance( int argc, int argv[] );
- QtUse::QtWorker::IPainter* CreatePainterInstance( void );
- // ウィンドウ系
- QtUse::QtWindow::IMainWindow* CreateMainWindowInstance( QWidget* parent, int id );
- }
- /* -+-+-+-+- DLL定義 -+-+-+-+- */
- namespace Crack{
- QString StringToQstring( const std::string str ){
- return QString::fromStdString( str );
- }
- std::string QstringToString( const QString &qstr ){
- return qstr.toStdString();
- }
- std::wstring QstringToWstring( const QString &qstr ){
- return qstr.toStdWString();
- }
- QLocale::Language LocalesetToQlocalelanguage( int nLocale ){
- if( nLocale == QtUse::LocaleSet::Japanese ){
- return QLocale::Japanese;
- }else if( nLocale == QtUse::LocaleSet::English ){
- return QLocale::QLocale::English;
- }else if( nLocale == QtUse::LocaleSet::Spanish ){
- return QLocale::QLocale::Spanish;
- }else if( nLocale == QtUse::LocaleSet::French ){
- return QLocale::QLocale::French;
- }else if( nLocale == QtUse::LocaleSet::Russian ){
- return QLocale::QLocale::Russian;
- }else if( nLocale == QtUse::LocaleSet::Latin ){
- return QLocale::QLocale::Latin;
- }else if( nLocale == QtUse::LocaleSet::Chinese ){
- return QLocale::QLocale::Chinese;
- }else if( nLocale == QtUse::LocaleSet::Italian ){
- return QLocale::QLocale::Italian;
- }
- // return -1;
- }
- int QlocalelanguageToLocaleset( QLocale::Language lang ){
- if( lang == QLocale::Japanese ){
- return QtUse::LocaleSet::Japanese;
- }else if( lang == QLocale::English ){
- return QtUse::LocaleSet::English;
- }else if( lang == QLocale::Spanish ){
- return QtUse::LocaleSet::Spanish;
- }else if( lang == QLocale::French ){
- return QtUse::LocaleSet::French;
- }else if( lang == QLocale::Russian ){
- return QtUse::LocaleSet::Russian;
- }else if( lang == QLocale::Latin ){
- return QtUse::LocaleSet::Latin;
- }else if( lang == QLocale::Chinese ){
- return QtUse::LocaleSet::Chinese;
- }else if( lang == QLocale::Italian ){
- return QtUse::LocaleSet::Italian;
- }else{
- return QtUse::LocaleSet::Unknown;
- }
- }
- QString ColorrefToQstringCss( QString objectName, COLORREF fore, COLORREF back ){
- std::string css;
- int r1, r2, g1, g2, b1, b2;
- QColor f( fore );
- QColor b( back );
- f.getRgb( &r1, &g1, &b1 );
- b.getRgb( &r2, &g2, &b2 );
- css = std::string( "#" );
- css += Crack::QstringToString( objectName );
- css += std::string( "{" );
- if( f.isValid() ){
- css += std::string( "color: rgb(" );
- css += std::to_string( r1 );
- css += std::string( "," );
- css += std::to_string( g1 );
- css += std::string( "," );
- css += std::to_string( b1 );
- css += std::string( ");" );
- }
- if( b.isValid() ){
- css += std::string( "background-color: rgb(" );
- css += std::to_string( r2 );
- css += std::string( "," );
- css += std::to_string( g2 );
- css += std::string( "," );
- css += std::to_string( b2 );
- css += std::string( ");" );
- }
- css += std::string( " }" );
- return Crack::StringToQstring( css );
- }
- QCursor CreateQcursor( const std::string filepath ){
- QPixmap p( StringToQstring( filepath ) );
- QCursor c( p );
- return c;
- }
- QIcon CreateQicon( const std::string filepath ){
- QPixmap p( StringToQstring( filepath ) );
- QIcon i( p );
- return i;
- }
- QFont LogfontToQfont( LOGFONT *lf ){
- QFont result;
- result.setPointSize( lf->lfHeight );
- if( lf->lfWeight == FW_BOLD ) result.setBold(true);
- else result.setBold(false);
- if( lf->lfItalic == TRUE ) result.setItalic(true);
- else result.setItalic(false);
- if( lf->lfUnderline == TRUE ) result.setUnderline(true);
- else result.setUnderline(false);
- if( lf->lfStrikeOut == TRUE ) result.setStrikeOut(true);
- else result.setStrikeOut(false);
- result.setFamily( lf->lfFaceName );
- return result;
- }
- LOGFONT QfontToLogfont( QFont* f ){
- LOGFONT result = { 0 };
- result.lfHeight = f->pointSize();
- if( f->bold() ) result.lfWeight = FW_BOLD;
- if( f->italic() ) result.lfItalic = TRUE;
- else result.lfItalic = FALSE;
- if( f->underline() ) result.lfUnderline = TRUE;
- else result.lfUnderline = FALSE;
- if( f->strikeOut() ) result.lfStrikeOut = TRUE;
- else result.lfStrikeOut = FALSE;
- strcpy( result.lfFaceName, Crack::QstringToString(f->family()).c_str() );
- return result;
- }
- QString CreateBorderCss( QString objectName, bool state ){
- std::string css;
- css = std::string( "#" );
- css += Crack::QstringToString( objectName );
- css += std::string( "{" );
- if( state ){
- css += std::string( "border: 1px solid black;" );
- }else{
- css += std::string( "border: none;" );
- }
- css += std::string( "}" );
- return Crack::StringToQstring( css );
- }
- QString CreateObjectName( const std::string TypeName, int id ){
- std::string name;
- name = std::string("Crack_") + TypeName + std::string("_") + std::to_string( id );
- return Crack::StringToQstring( name );
- }
- int CalcIdFromObjectName( const QString objectName ){
- int result;
- int pos;
- std::string temp;
- temp = Crack::QstringToString( objectName );
- pos = temp.find_last_of( "_" );
- temp.replace( 0, pos + 1, "" );
- {
- bool ok;
- QString converter;
- converter = Crack::StringToQstring( temp );
- result = converter.toInt( &ok );
- if( ok ){
- return result;
- }else{
- return -1;
- }
- }
- }
- }
- namespace QtRrcConcrete{
- CCursor::CCursor( int id ) : id_(id){}
- CCursor::~CCursor(){}
- bool CCursor::fromFile( const std::string filepath ){
- cur_ = Crack::CreateQcursor( filepath );
- }
- QCursor CCursor::cur( void ){
- return cur_;
- }
- bool CCursor::empty( void ){
- if( cur_.pixmap().isNull() ){
- if( cur_.bitmap()->isNull() ){
- return true;
- }else{
- return false;
- }
- }else{
- return false;
- }
- }
- }
- namespace QtRrcConcrete{
- CIcon::CIcon( int id ) : id_(id){}
- CIcon::~CIcon(){}
- bool CIcon::fromFile( const std::string filepath ){
- ico_ = Crack::CreateQicon( filepath );
- }
- QIcon CIcon::ico( void ){
- return ico_;
- }
- bool CIcon::empty( void ){
- return ico_.isNull();
- }
- }
- namespace QtRrcConcrete{
- CImage::CImage( int id ) : id_(id){}
- CImage::~CImage(){}
- bool CImage::fromFile( const std::string filepath ){
- img_.load( Crack::StringToQstring( filepath ) );
- }
- QImage CImage::img( void ){
- return img_;
- }
- int CImage::height( void ){
- return img_.height();
- }
- int CImage::width( void ){
- return img_.width();
- }
- bool CImage::empty( void ){
- return img_.isNull();
- }
- }
- namespace QtWorkerConcrete{
- CApplication::CApplication( int argc, char *argv[] ){
- app = new QApplication( argc, argv );
- }
- CApplication::~CApplication(){
- delete app;
- }
- void CApplication::setIcon( QtUse::QtRrc::IIcon* icon ){
- app->setWindowIcon( icon->ico() );
- return;
- }
- int CApplication::exec( void ){
- return app->exec();
- }
- }
- namespace QtWorkerConcrete{
- CPainter::CPainter(){}
- CPainter::~CPainter(){}
- bool CPainter::begin( QtUse::QtWindow::IWindow* window ){
- return painter.begin( window->widget() );
- }
- bool CPainter::end( void ){
- return painter.end();
- }
- bool CPainter::show( int x, int y, int height, int width, QtUse::QtRrc::IImage* image ){
- int h, w;
- QPixmap p;
- if( image->empty() ) return false;
- p = QPixmap::fromImage( image->img() );
- if( height <= 0 ){
- h = image->height();
- }else{
- h = height;
- }
- if( width <= 0 ){
- w = image->width();
- }else{
- w = width;
- }
- painter.drawPixmap( x, y, w, h, p, 0, 0, image->width(), image->height() );
- return true;
- }
- }
- namespace QtWindowConcrete{
- WMainWindow::WMainWindow( QWidget* parent, int id ) : id_(id){
- event_ = nullptr;
- // QMainWindow::setObjectName( Crack::CreateObjectName( "MainWindow", id_ ) );
- this->show();
- }
- WMainWindow::~WMainWindow(){
- }
- QWidget* WMainWindow::widget( void ) const{
- }
- HWND WMainWindow::hWnd( void ) const{
- }
- int WMainWindow::id( void ) const{
- }
- void WMainWindow::setFont( LOGFONT lf ){
- }
- LOGFONT WMainWindow::font( void ) const{
- }
- void WMainWindow::setCursor( QtUse::QtRrc::ICursor* cursor ){
- }
- void WMainWindow::setAcceptDrops( bool state ){
- }
- bool WMainWindow::acceptDrops( void ) const{
- }
- void WMainWindow::setLocale( int nLocale ){
- }
- int WMainWindow::locale( void ) const{
- }
- void WMainWindow::setToolTip( const std::string msg ){
- }
- std::string WMainWindow::toolTip( void ) const{
- }
- void WMainWindow::setColor( COLORREF foreColor, COLORREF bgColor ){
- }
- void WMainWindow::show( void ){
- QMainWindow::show();
- return;
- }
- void WMainWindow::hide( void ){
- }
- void WMainWindow::move( int x, int y ){
- }
- int WMainWindow::x( void ) const{
- }
- int WMainWindow::y( void ) const{
- }
- void WMainWindow::resize( int height, int width ){
- }
- int WMainWindow::height( void ) const{
- }
- int WMainWindow::width( void ) const{
- }
- void WMainWindow::setVisible( bool state ){
- }
- bool WMainWindow::visible( void ) const{
- }
- void WMainWindow::setEnabled( bool state ){
- }
- bool WMainWindow::isEnabled( void ) const{
- }
- void WMainWindow::setFocus( void ){
- }
- bool WMainWindow::focus( void ) const{
- }
- void WMainWindow::setText( const std::string text ){
- }
- std::string WMainWindow::getText( void ) const{
- }
- void WMainWindow::setIcon( QtUse::QtRrc::IIcon* icon ){
- }
- int WMainWindow::addEvent( QtUse::QtEvent::IMainWindowEvent* event ){
- }
- }
- namespace Factories{
- // リソース系
- QtUse::QtRrc::ICursor* CreateCursorInstance( int id ){
- return new QtRrcConcrete::CCursor( id );
- }
- QtUse::QtRrc::IIcon* CreateIconInstance( int id ){
- return new QtRrcConcrete::CIcon( id );
- }
- QtUse::QtRrc::IImage* CreateImageInstance( int id ){
- return new QtRrcConcrete::CImage( id );
- }
- // ワーカ系
- QtUse::QtWorker::IApplication* CreateApplicationInstance( int argc, char *argv[] ){
- return new QtWorkerConcrete::CApplication( argc, argv );
- }
- QtUse::QtWorker::IPainter* CreatePainterInstance( void ){
- return new QtWorkerConcrete::CPainter();
- }
- // ウィンドウ系
- QtUse::QtWindow::IMainWindow* CreateMainWindowInstance( QWidget* parent, int id ){
- if( parent == nullptr ){
- return new QtWindowConcrete::WMainWindow( Q_NULLPTR, id );
- }else{
- return new QtWindowConcrete::WMainWindow( parent, id );
- }
- }
- }
- /* -+-+-+-+- 実行ファイル側 -+-+-+-+- */
- namespace QtInstanceDesigner{
- class QtFactory{
- public:
- QtFactory(){} // 本来ならここでDLLリンク
- ~QtFactory(){} // 本来ならここでDLLリンク破棄
- QtUse::QtRrc::ICursor* createCursor( int id ){
- return Factories::CreateCursorInstance( id );
- }
- QtUse::QtRrc::IIcon* createIcon( int id ){
- return Factories::CreateIconInstance( id );
- }
- QtUse::QtRrc::IImage* createImage( int id ){
- return Factories::CreateImageInstance( id );
- }
- QtUse::QtWorker::IApplication* createApplication( int argc, char *argv[] ){
- return Factories::CreateApplicationInstance( argc, argv );
- }
- QtUse::QtWorker::IPainter* createPainter( void ){
- return Factories::CreatePainterInstance();
- }
- QtUse::QtWindow::IMainWindow* createMainWindow( QWidget* parent, int id ){
- return Factories::CreateMainWindowInstance( parent, id );
- }
- private:
- };
- }
- namespace WindowX{
- class IMain{
- public:
- virtual ~IMain(){}
- protected:
- virtual int main( int argc, char* argv[] ) = 0;
- virtual void init( void ) = 0;
- virtual void uninit( void ) = 0;
- virtual void setup( void ) = 0;
- };
- class CMain : public IMain{
- public:
- CMain(){
- factory = new QtInstanceDesigner::QtFactory();
- }
- ~CMain(){
- delete factory;
- }
- int operator()( int argc, char *argv[] ){
- return this->main( argc, argv );
- }
- public:
- // ここにイベント系
- private:
- void init( void ){
- window = factory->createMainWindow( nullptr, 1 );
- }
- void uninit( void ){
- delete window;
- }
- void setup( void ){
- window->show();
- }
- int main( int argc, char* argv[] ){
- app = factory->createApplication( argc, argv );
- this->init();
- MsgBox( "1" );
- this->setup();
- MsgBox( "2" );
- int res = app->exec();
- MsgBox( "3" );
- this->uninit();
- MsgBox( "4" );
- delete app;
- MsgBox( "5" );
- return res;
- }
- private:
- QtUse::QtWindow::IMainWindow* window;
- QtUse::QtWorker::IApplication* app;
- private:
- QtInstanceDesigner::QtFactory* factory;
- };
- }
- int main( int argc, char *argv[] ){
- WindowX::CMain Main;
- return Main( argc, argv );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement