Commit bda7c1ed authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

crossplatform MainPanel and test app.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@64308 954022d7-b5bf-4e40-9824-e11837661b57
parent fdb25af6
...@@ -815,6 +815,52 @@ DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/Icons/tabicon_SE_normal.png s ...@@ -815,6 +815,52 @@ DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/Icons/tabicon_SE_normal.png s
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/Release svnc_tsvn_003alogminsize=5 DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/Release svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/asceditor_32.ico svn_mime_002dtype=application%2Foctet-stream DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/asceditor_32.ico svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/asceditor_64.ico svn_mime_002dtype=application%2Foctet-stream DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/asceditor_64.ico svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/Documents_active_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/Documents_active_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/Documents_disabled_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/Documents_disabled_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_left_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_left_disabled.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_left_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_left_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_right_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_right_disabled.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_right_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/changetab_right_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/collapse_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/collapse_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/collapse_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/deploy2_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/deploy2_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/deploy2_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/deploy_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/deploy_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/deploy_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/exit_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/exit_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/exit_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/first_tab_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/first_tab_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/first_tab_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_collapse_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_collapse_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_deploy2_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_deploy2_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_deploy_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_deploy_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_exit_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/new_exit_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/output_tab_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/output_tab_hover.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/output_tab_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/tabicon_DE_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/tabicon_DE_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/tabicon_PE_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/tabicon_PE_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/tabicon_SE_active.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/app/test/src/Icons/tabicon_SE_normal.png svn_mime_002dtype=application%2Foctet-stream
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib svnc_tsvn_003alogminsize=5 DesktopEditor/ChromiumBasedEditors[!!-~]2/lib svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/include svnc_tsvn_003alogminsize=5 DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/include svnc_tsvn_003alogminsize=5
DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/qcefview svnc_tsvn_003alogminsize=5 DesktopEditor/ChromiumBasedEditors[!!-~]2/lib/qcefview svnc_tsvn_003alogminsize=5
QT += core gui widgets printsupport
TEMPLATE = app
CONFIG += app_bundle
CONFIG -= debug_and_release debug_and_release_target
CONFIG(debug, debug|release) {
DESTDIR = $$PWD/build/windows/Debug
} else {
DESTDIR = $$PWD/build/windows/Release
}
win32:contains(QMAKE_TARGET.arch, x86_64):{
PLATFORM_BUILD = win64
message(windows64)
}
win32:!contains(QMAKE_TARGET.arch, x86_64):{
PLATFORM_BUILD = win32
message(windows32)
}
CONFIG(debug, debug|release) {
PLATFORM_BUILD2 = $$PLATFORM_BUILD/debug
message(debug)
} else {
PLATFORM_BUILD2 = $$PLATFORM_BUILD
}
include($$PWD/AscDocumentEditor.pri)
SOURCES += \
$$PWD/main.cpp
LIBS += -L$$PWD/../../cefbuilds/$$PLATFORM_BUILD -llibcef
LIBS += -L$$PWD/../../corebuilds/$$PLATFORM_BUILD2 -lascdocumentscore
HEADERS += \
$$PWD/../../../lib/qcefview/qcefview.h \
$$PWD/../../../lib/include/qascprinter.h
SOURCES += \
$$PWD/../../../lib/qcefview/qcefview.cpp
HEADERS += \
$$PWD/QAscApplicationManager.h \
$$PWD/QAscTabWidget.h \
$$PWD/QAscMainPanel.h \
$$PWD/QAscMain.h
SOURCES += \
$$PWD/QAscMainPanel.cpp
RESOURCES += \
Icons.qrc
win32 {
LIBS += -lwininet \
-ldnsapi \
-lversion \
-lmsimg32 \
-lws2_32 \
-lusp10 \
-lpsapi \
-ldbghelp \
-lwinmm \
-lshlwapi \
-lkernel32 \
-lgdi32 \
-lwinspool \
-lcomdlg32 \
-ladvapi32 \
-lshell32 \
-lole32 \
-loleaut32 \
-luser32 \
-luuid \
-lodbc32 \
-lodbccp32 \
-ldelayimp \
-lcredui \
-lnetapi32 \
-lcomctl32 \
-lrpcrt4 \
-ldwmapi \
-lOpenGL32
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.02
}
<RCC>
<qresource prefix="/">
<file>Icons/collapse_active.png</file>
<file>Icons/collapse_hover.png</file>
<file>Icons/collapse_normal.png</file>
<file>Icons/deploy_active.png</file>
<file>Icons/deploy_hover.png</file>
<file>Icons/deploy_normal.png</file>
<file>Icons/exit_active.png</file>
<file>Icons/exit_hover.png</file>
<file>Icons/exit_normal.png</file>
<file>Icons/first_tab_active.png</file>
<file>Icons/first_tab_hover.png</file>
<file>Icons/first_tab_normal.png</file>
<file>Icons/output_tab_active.png</file>
<file>Icons/output_tab_hover.png</file>
<file>Icons/output_tab_normal.png</file>
<file>Icons/tabicon_DE_active.png</file>
<file>Icons/tabicon_DE_normal.png</file>
<file>Icons/tabicon_PE_active.png</file>
<file>Icons/tabicon_PE_normal.png</file>
<file>Icons/tabicon_SE_active.png</file>
<file>Icons/tabicon_SE_normal.png</file>
<file>Icons/changetab_left_active.png</file>
<file>Icons/changetab_left_hover.png</file>
<file>Icons/changetab_left_normal.png</file>
<file>Icons/changetab_right_active.png</file>
<file>Icons/changetab_right_hover.png</file>
<file>Icons/changetab_right_normal.png</file>
<file>Icons/changetab_left_disabled.png</file>
<file>Icons/changetab_right_disabled.png</file>
<file>Icons/deploy2_active.png</file>
<file>Icons/deploy2_hover.png</file>
<file>Icons/deploy2_normal.png</file>
<file>Icons/Documents_active_hover.png</file>
<file>Icons/Documents_active_normal.png</file>
<file>Icons/Documents_disabled_hover.png</file>
<file>Icons/Documents_disabled_normal.png</file>
<file>Icons/new_collapse_normal.png</file>
<file>Icons/new_deploy_hover.png</file>
<file>Icons/new_deploy_normal.png</file>
<file>Icons/new_exit_hover.png</file>
<file>Icons/new_exit_normal.png</file>
<file>Icons/new_deploy2_hover.png</file>
<file>Icons/new_deploy2_normal.png</file>
<file>Icons/new_collapse_hover.png</file>
</qresource>
</RCC>
#ifndef QASCAPPLICATIONMANAGER
#define QASCAPPLICATIONMANAGER
#include "../../../lib/include/cefapplication.h"
#include "../../../lib/include/applicationmanager.h"
#include <shlwapi.h>
#include <shlobj.h>
#include <QFileDialog>
#include "QAscMainPanel.h"
class QAscApplicationManager : public CAscApplicationManager
{
public:
QAscMainPanel* m_pPanel;
public:
QAscApplicationManager()
{
m_pPanel = NULL;
}
public:
virtual void StartSaveDialog(const std::wstring& sName)
{
// сделал через QMainPanel - чтобы использовать сигналы-слоты.
// если сделать QAscApplicationManager : public QObject, то он будет прокидывать
// слоты родителю. Т.е. классу CAscApplicationManager.
// А в либе я не буду затачиваться на QT
((QAscMainPanel*)m_pPanel)->sendDialogSave(sName);
}
};
#endif // QASCAPPLICATIONMANAGER
#ifndef ASCEDITORWIDGET
#define ASCEDITORWIDGET
#include <QWidget>
#include <QTabWidget>
#include <QTabBar>
#include <QStyleOption>
#include <QPainter>
#include <QApplication>
namespace NSAscEditor
{
enum EditorType
{
etDocument = 0,
etPresentation = 1,
etSpreadsheet = 2
};
}
#if 0
class CAscEditorWidget : public QWidget
{
Q_OBJECT
public:
NSAscEditor::EditorType m_etType;
public:
CAscEditorWidget(QWidget *parent = 0, NSAscEditor::EditorType etType = NSAscEditor::etDocument) : QWidget(parent)
{
m_etType = etType;
setStyleSheet("background-color:#FF00FF");
}
~CAscEditorWidget()
{
}
void SetIcon(int nIndex, QTabWidget* pWidget)
{
int nSelectedIndex = pWidget->tabBar()->currentIndex();
QTabBar* pTabBar = pWidget->tabBar();
bool bIsActive = (nIndex == nSelectedIndex) ? true : false;
switch (m_etType)
{
case NSAscEditor::etPresentation:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_PE_active.png") : QIcon(":/Icons/tabicon_PE_normal.png"));
break;
}
case NSAscEditor::etSpreadsheet:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_SE_active.png") : QIcon(":/Icons/tabicon_SE_normal.png"));
break;
}
case NSAscEditor::etDocument:
default:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_DE_active.png") : QIcon(":/Icons/tabicon_DE_normal.png"));
break;
}
}
pTabBar->setTabTextColor(nIndex, bIsActive ? QColor(255, 255, 255) : QColor(51, 51, 51));
}
protected:
void paintEvent(QPaintEvent* e)
{
Q_UNUSED(e);
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
};
#else
#include "./cef/qcefwebview.h"
class CAscEditorWidget : public QCefWebView
{
Q_OBJECT
public:
NSAscEditor::EditorType m_etType;
public:
CAscEditorWidget(QWidget *parent = 0, NSAscEditor::EditorType etType = NSAscEditor::etDocument, std::wstring strUrl = L"") : QCefWebView(parent)
{
this->setParentTabs((QTabWidget*)parent);
m_etType = etType;
std::wstring sUrl = QApplication::applicationDirPath().toStdWString();
sUrl += L"/deploy/apps/api/documents/index.html";
if (etType == NSAscEditor::etSpreadsheet)
sUrl += L"?doctype=spreadsheet";
if (etType == NSAscEditor::etPresentation)
sUrl += L"?doctype=presentation";
if (strUrl.length() != 0)
sUrl = strUrl;
this->load(sUrl);
}
virtual ~CAscEditorWidget()
{
}
void SetIcon(int nIndex, QTabWidget* pWidget)
{
int nSelectedIndex = pWidget->tabBar()->currentIndex();
QTabBar* pTabBar = pWidget->tabBar();
bool bIsActive = (nIndex == nSelectedIndex) ? true : false;
switch (m_etType)
{
case NSAscEditor::etPresentation:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_PE_active.png") : QIcon(":/Icons/tabicon_PE_normal.png"));
break;
}
case NSAscEditor::etSpreadsheet:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_SE_active.png") : QIcon(":/Icons/tabicon_SE_normal.png"));
break;
}
case NSAscEditor::etDocument:
default:
{
pTabBar->setTabIcon(nIndex, bIsActive ? QIcon(":/Icons/tabicon_DE_active.png") : QIcon(":/Icons/tabicon_DE_normal.png"));
break;
}
}
//pTabBar->setTabTextColor(nIndex, bIsActive ? QColor(255, 255, 255) : QColor(51, 51, 51));
pTabBar->setTabTextColor(nIndex, QColor(51, 51, 51));
}
};
#endif
#endif // ASCEDITORWIDGET
#pragma once
#include <QFile>
#include <QScreen>
#include <QDir>
#include "QAscApplicationManager.h"
#include "QAscMainPanel.h"
#ifdef WIN32
#include <shlwapi.h>
#include <shlobj.h>
#endif
#include <QStandardPaths>
static std::wstring GetAppDataPath()
{
#ifdef WIN32
WCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath ) ) )
{
// TODO: [0]
// QStringList arr = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
// Append product-specific path
std::wstring sAppData(szPath);
sAppData += L"/ONLYOFFICE";
return sAppData;
}
#else
std::wstring sAppData = QDir::homePath().toStdWString();
sAppData += L"/ONLYOFFICE";
return sAppData;
#endif
return L"";
}
#include <QMainWindow>
#include <QApplication>
class QAscMainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit QAscMainWindow(QWidget *parent, CAscApplicationManager* pAppManager) : QMainWindow(parent)
{
this->resize(1000, 500);
QWidget* pMainPanel = new QAscMainPanel(this, pAppManager);
this->setCentralWidget(pMainPanel);
((QAscApplicationManager*)pAppManager)->m_pPanel = (QAscMainPanel*)pMainPanel;
QMetaObject::connectSlotsByName(this);
}
~QAscMainWindow()
{
}
};
static int AscEditor_Main( int argc, char *argv[] )
{
bool bIsChromiumSubprocess = false;
for (int i = 0; i < argc; ++i)
{
if ((0 == strcmp("--type=gpu-process", argv[i])) ||
(0 == strcmp("--type=renderer", argv[i])) ||
(0 == strcmp("--type=zygote", argv[i])))
{
bIsChromiumSubprocess = true;
break;
}
}
#if 0
FILE* f = fopen("E:\\12345.txt", "a+");
fprintf(f, "-----------------------------------------------\n");
for (int i = 0; i < argc; ++i)
{
fprintf(f, argv[i]);
fprintf(f, "\n");
}
fprintf(f, "-----------------------------------------------\n");
fclose(f);
#endif
if (bIsChromiumSubprocess)
{
QApplication aa(argc, argv);
CApplicationCEF oCef;
CAscApplicationManager oManager;
std::wstring sUserPath = GetAppDataPath();
oManager.m_oSettings.SetUserDataPath(sUserPath);
oCef.Init_CEF(&oManager);
return aa.exec();
}
QApplication a(argc, argv);
CApplicationCEF* application_cef = new CApplicationCEF();
CAscApplicationManager* pApplicationManager = new QAscApplicationManager();
std::wstring sUserPath = GetAppDataPath();
pApplicationManager->m_oSettings.SetUserDataPath(sUserPath);
qreal ww = a.primaryScreen()->logicalDotsPerInch();
qreal hh = a.primaryScreen()->physicalDotsPerInch();
application_cef->Init_CEF(pApplicationManager);
pApplicationManager->CheckFonts();
a.setStyleSheet("#mainPanel { margin: 0; padding: 0; }\
#systemPanel { margin: 0; padding: 0; } \
#centralWidget { background: #fff; }");
// Font
QFont mainFont = a.font();
mainFont.setStyleStrategy( QFont::PreferAntialias );
a.setFont( mainFont );
// Background color
HBRUSH windowBackground = CreateSolidBrush( RGB( 49, 52, 55 ) );
// Create window
QAscMainWindow w(NULL, pApplicationManager);
w.show();
// Launch
a.exec();
// release all subprocesses
pApplicationManager->CloseApplication();
delete application_cef;
delete pApplicationManager;
return 0;
}
#include <windows.h>
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QPushButton>
#include <QScrollArea>
#include <QFileDialog>
#include "QAscMainPanel.h"
#include "QAscTabWidget.h"
#include <QStandardPaths>
#include "../../../lib/include/qascprinter.h"
QAscMainPanel::QAscMainPanel( QWidget* parent, CAscApplicationManager* pManager ) : QWidget( parent )
{
QObject::connect(this, SIGNAL( downloadEvent(NSEditorApi::CAscDownloadFileInfo*) ), this, SLOT( downloadEventSlot(NSEditorApi::CAscDownloadFileInfo*) ), Qt::QueuedConnection );
QObject::connect(this, SIGNAL( setModified(int,bool)) , this, SLOT( onSetModified(int,bool)), Qt::QueuedConnection );
QObject::connect(this, SIGNAL( signalPrint(int,int)) , this, SLOT( slotPrint(int,int)), Qt::QueuedConnection );
QObject::connect(this, SIGNAL( dialogSave()), this, SLOT( onDialogSave()), Qt::QueuedConnection);
m_pManager = pManager;
setObjectName( "mainPanel" );
QGridLayout *mainGridLayout = new QGridLayout();
mainGridLayout->setSpacing( 0 );
mainGridLayout->setMargin( 0 );
setLayout( mainGridLayout );
// Central widget
QWidget *centralWidget = new QWidget( this );
centralWidget->setObjectName( "centralWidget" );
centralWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
centralWidget->setStyleSheet("background-color:#313437");
QWidget *centralWidget2 = new QWidget( centralWidget );
centralWidget->setObjectName( "centralWidget" );
centralWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
QAscTabWidget* pTabs = new QAscTabWidget(centralWidget);
pTabs->setGeometry(0, 0, centralWidget->width(), centralWidget->height());
pTabs->m_pManager = m_pManager;
m_pTabs = (QTabWidget*)pTabs;
m_pSaveModifiedButton = new QPushButton("", centralWidget);
m_pSaveModifiedButton->setObjectName( "pushButtoneModified" );
QObject::connect( m_pSaveModifiedButton, SIGNAL( clicked() ), this, SLOT( pushButtonSaveClicked()) );
m_pSaveModifiedButton->setStyleSheet("background-color:#FFFFFF;border:none;margin:0;padding:0;");
// Minimize
m_pButtonMinimize = new QPushButton( "", centralWidget );
m_pButtonMinimize->setObjectName( "pushButtonMinimize" );
QObject::connect( m_pButtonMinimize, SIGNAL( clicked() ), this, SLOT( pushButtonMinimizeClicked() ) );
m_pButtonMinimize->setStyleSheet("QPushButton {background-image:url(:/Icons/new_collapse_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/new_collapse_hover.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/new_collapse_hover.png);border:none;margin:0;padding:0;}");
// Maximize
m_pButtonMaximize = new QPushButton( "", centralWidget );
m_pButtonMaximize->setObjectName( "pushButtonMaximize" );
QObject::connect( m_pButtonMaximize, SIGNAL( clicked() ), this, SLOT( pushButtonMaximizeClicked() ) );
m_pButtonMaximize->setStyleSheet("QPushButton {background-image:url(:/Icons/new_deploy_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/new_deploy_hover.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/new_deploy_hover.png);border:none;margin:0;padding:0;}");
// Close
m_pButtonClose = new QPushButton( "", centralWidget );
m_pButtonClose->setObjectName( "pushButtonClose" );
QObject::connect( m_pButtonClose, SIGNAL( clicked() ), this, SLOT( pushButtonCloseClicked() ) );
m_pButtonClose->setStyleSheet("QPushButton {background-image:url(:/Icons/new_exit_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/new_exit_hover.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/new_exit_hover.png);border:none;margin:0;padding:0;}");
// Main
m_pButtonMain = new QPushButton( "", centralWidget );
m_pButtonMain->setObjectName( "pushButtonMain" );
QObject::connect( m_pButtonMain, SIGNAL( clicked() ), this, SLOT( pushButtonMainClicked() ) );
m_pButtonMain->setStyleSheet("QPushButton {background-image:url(:/Icons/Documents_active_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/Documents_active_normal.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/Documents_active_hover.png);border:none;margin:0;padding:0;}");
QCefView* pMainWidget = new QCefView(centralWidget);
pMainWidget->Create(m_pManager, cvwtSimple);
pMainWidget->setObjectName( "mainPanel" );
pMainWidget->setHidden(false);
//pMainWidget->GetCefView()->load(L"https://ascdesktop.teamlab.info/products/files/?desktop=true");
//pMainWidget->GetCefView()->load(L"https://testinfo.teamlab.info/products/files/?desktop=true");
//pMainWidget->GetCefView()->load(L"https://denisdenis.teamlab.info/products/files/?desktop=true");
//pMainWidget->GetCefView()->load(L"https://denismy.teamlab.info/products/files/?desktop=true");
//pMainWidget->GetCefView()->load(L"file:///C:/Users/oleg.korshul/Desktop/desktop/index.html");
//pMainWidget->GetCefView()->load(L"file:///C:/Users/oleg.korshul/Desktop/desktop2/index.html");
pMainWidget->GetCefView()->load(L"https://koroleg.teamlab.info/products/files/?desktop=true");
//pMainWidget->GetCefView()->load(L"http://isa2:8086");
m_pMainWidget = (QWidget*)pMainWidget;
pTabs->m_pMainWidget = m_pMainWidget;
pTabs->m_pMainButton = m_pButtonMain;
m_pSeparator = new QWidget(centralWidget);
m_pSeparator->setObjectName("separator");
m_pSeparator->setStyleSheet("background-color:#D6D6D7");
m_pSeparator->setGeometry(0, 28, this->width(), 1);
mainGridLayout->addWidget( centralWidget );
m_pDownloadBackground = new QWidget(centralWidget);
m_pDownloadBackground->setObjectName("downloadBackground");
m_pDownloadBackground->setStyleSheet("background-color:#646464;");
m_pDownloadLable = new QLabel(m_pDownloadBackground);
m_pDownloadLable->setObjectName("downloadLable");
#if 1
QPalette palette;
//white text
QBrush brush(QColor(0, 0, 0, 255));
brush.setStyle(Qt::SolidPattern);
//black background
QBrush brush1(QColor(0x64, 0x64, 0x64, 255));
brush1.setStyle(Qt::SolidPattern);
//set white text
palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
palette.setBrush(QPalette::Inactive, QPalette::WindowText, brush);
//set black background
palette.setBrush(QPalette::Active, QPalette::Window, brush1);
palette.setBrush(QPalette::Inactive, QPalette::Window, brush1);
//set palette
m_pDownloadLable->setPalette(palette);
//set font
QFont font;
font.setPixelSize(32);
font.setBold(true);
m_pDownloadLable->setFont(font);
m_pDownloadLable->setAutoFillBackground(true);
m_pDownloadLable->setText("Oleg");
#endif
m_pDownloadBackground->setHidden(true);
RecalculatePlaces();
show();
m_pManager->SetEventListener(this);
}
void QAscMainPanel::RecalculatePlaces()
{
int nWindowW = this->width();
int nWindowH = this->height();
int nCaptionH = 29;
m_pTabs->setGeometry(0, 0, nWindowW, nWindowH);
m_pButtonMain->setGeometry(0, 0, 108, nCaptionH);
m_pSeparator->setGeometry(0, 28, this->width(), 1);
int nStartOffset = 12;
int nBetweenApp = 12;
int nButtonW = 12;
int nY = (nCaptionH - nButtonW) >> 1;
nY = 5;
m_pButtonClose->setGeometry(nWindowW - nStartOffset - nButtonW, nY, nButtonW, nButtonW);
m_pButtonMaximize->setGeometry(nWindowW - nStartOffset - 2 * nButtonW - nBetweenApp, nY, nButtonW, nButtonW);
m_pButtonMinimize->setGeometry(nWindowW - nStartOffset - 3 * nButtonW - 2 * nBetweenApp, nY, nButtonW, nButtonW);
m_pSaveModifiedButton->setGeometry(nWindowW - nStartOffset - 4 * nButtonW - 3 * nBetweenApp, nY, nButtonW, nButtonW);
m_pMainWidget->setGeometry(0, nCaptionH, nWindowW, nWindowH - nCaptionH);
m_pDownloadBackground->setGeometry(0, nWindowH - 100, nWindowW, 100);
m_pDownloadLable->setGeometry(0, 0, nWindowW, 100);
}
void QAscMainPanel::pushButtonSaveClicked()
{
#if 0
int nCount = m_pTabs->tabBar()->count();
for (int i = 0; i < nCount; ++i)
{
if (i != m_pTabs->tabBar()->currentIndex())
{
CCefView* pCefView = ((QCefView*)m_pTabs->widget(m_pTabs->tabBar()->currentIndex()))->GetCefView();
pCefView->focus(false);
}
}
return;
#endif
#if 0
if (-1 != m_pTabs->tabBar()->currentIndex())
{
CCefView* pCefView = ((QCefView*)m_pTabs->widget(m_pTabs->tabBar()->currentIndex()))->GetCefView();
NSEditorApi::CAscMenuEvent* pEvent = new NSEditorApi::CAscMenuEvent();
pEvent->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_START;
pCefView->Apply(pEvent);
}
#endif
if (m_pSaveModifiedButton->styleSheet() != "background-color:#00FF00;border:none;margin:0;padding:0;")
return;
bool bIsMain = !m_pMainWidget->isHidden();
if (bIsMain)
return;
if (-1 == m_pTabs->tabBar()->currentIndex())
return;
CCefView* pCefView = ((QCefView*)m_pTabs->widget(m_pTabs->tabBar()->currentIndex()))->GetCefView();
NSEditorApi::CAscMenuEvent* pEvent = new NSEditorApi::CAscMenuEvent();
pEvent->m_nType = ASC_MENU_EVENT_TYPE_CEF_SAVE;
pCefView->Apply(pEvent);
}
void QAscMainPanel::pushButtonMainClicked()
{
// test logout
//m_pManager->Logout(L"ascdesktop.teamlab.info");
m_pMainWidget->setHidden(!m_pMainWidget->isHidden());
if (m_pMainWidget->isHidden())
{
m_pButtonMain->setStyleSheet("QPushButton {background-image:url(:/Icons/Documents_disabled_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/Documents_disabled_normal.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/Documents_disabled_hover.png);border:none;margin:0;padding:0;}");
((QCefView*)m_pMainWidget)->GetCefView()->focus();
}
else
{
m_pButtonMain->setStyleSheet("QPushButton {background-image:url(:/Icons/Documents_active_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/Documents_active_normal.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/Documents_active_hover.png);border:none;margin:0;padding:0;}");
((QAscTabWidget*)m_pTabs)->FireFocus();
m_pTabs->setCurrentIndex(-1);
}
}
void QAscMainPanel::downloadEventSlot(NSEditorApi::CAscDownloadFileInfo* pInfo)
{
if (pInfo->get_IsComplete())
{
// файл докачался, нужно удалить его из списка
std::map<int, NSEditorApi::CAscDownloadFileInfo*>::iterator i = m_mapDownloads.find(pInfo->get_Id());
if (i != m_mapDownloads.end())
{
RELEASEINTERFACE((i->second));
m_mapDownloads.erase(i);
}
}
else
{
std::map<int, NSEditorApi::CAscDownloadFileInfo*>::iterator i = m_mapDownloads.find(pInfo->get_Id());
if (i != m_mapDownloads.end())
{
NSEditorApi::CAscDownloadFileInfo* pCurrent = i->second;
pCurrent->put_Percent(pInfo->get_Percent());
pCurrent->put_Speed(pInfo->get_Speed());
pCurrent->put_IsComplete(pInfo->get_IsComplete());
}
else
{
if (!pInfo->get_FilePath().empty())
{
ADDREFINTERFACE(pInfo);
m_mapDownloads.insert(std::pair<int, NSEditorApi::CAscDownloadFileInfo*>(pInfo->get_Id(), pInfo));
}
}
}
RELEASEINTERFACE(pInfo);
// теперь смотрим, нужно ли показывать загрузки
if (0 == m_mapDownloads.size())
{
m_pDownloadBackground->setHidden(true);
return;
}
m_pDownloadBackground->setHidden(false);
QString sText = "";
for (std::map<int, NSEditorApi::CAscDownloadFileInfo*>::iterator i = m_mapDownloads.begin(); i != m_mapDownloads.end(); i++)
{
NSEditorApi::CAscDownloadFileInfo* pInfo = i->second;
std::wstring sName = pInfo->get_FilePath();
int n1 = sName.find_last_of((wchar_t)'\\');
int n2 = sName.find_last_of((wchar_t)'/');
int n = -1;
if (n1 != std::wstring::npos)
n = n1;
if (n2 != std::wstring::npos && n2 > n1)
n = n2;
if (-1 == n)
continue;
sName = sName.substr(n + 1);
sName += L" : %1; ";
QString ss = QString::fromStdWString(sName);
int nPercent = pInfo->get_Percent();
if (nPercent < 0)
nPercent = 0;
sText += ss.arg(nPercent);
}
m_pDownloadLable->setText(sText);
}
void QAscMainPanel::onSetModified(int id, bool value)
{
bool bIsMain = !m_pMainWidget->isHidden();
if (bIsMain)
return;
int nTabIndex = ((QAscTabWidget*)m_pTabs)->GetTabIndexById(id);
if (nTabIndex == m_pTabs->tabBar()->currentIndex())
{
if (value == true)
m_pSaveModifiedButton->setStyleSheet("background-color:#00FF00;border:none;margin:0;padding:0;");
else
m_pSaveModifiedButton->setStyleSheet("background-color:#FFFFFF;border:none;margin:0;padding:0;");
}
}
void QAscMainPanel::slotPrint(int id, int pagesCount)
{
QAscPrinterContext* pContext = new QAscPrinterContext();
//pagesCount = 1;
pContext->getPrinter()->setFromTo(1, pagesCount);
QPrintDialog *dialog = new QPrintDialog(pContext->getPrinter(), NULL);
dialog->setWindowTitle(tr("Print Document"));
dialog->show();
CCefView* pView = m_pManager->GetViewById(id);
pContext->BeginPaint();
for (int i = 0; i < pagesCount; ++i)
{
pContext->AddRef();
NSEditorApi::CAscPrintPage* pData = new NSEditorApi::CAscPrintPage();
pData->put_Context(pContext);
pData->put_Page(i);
NSEditorApi::CAscMenuEvent* pEvent = new NSEditorApi::CAscMenuEvent();
pEvent->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_PAGE;
pEvent->m_pData = pData;
pView->Apply(pEvent);
if (i != (pagesCount - 1))
pContext->getPrinter()->newPage();
}
pContext->EndPaint();
NSEditorApi::CAscMenuEvent* pEventEnd = new NSEditorApi::CAscMenuEvent();
pEventEnd->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_END;
pView->Apply(pEventEnd);
pContext->Release();
}
void QAscMainPanel::onDialogSave()
{
std::wstring sName = m_sDownloadName;
QStringList arDocumentsPath = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
QString sDocumentsPath = (arDocumentsPath.size() == 0) ? QString() : arDocumentsPath[0];
sDocumentsPath += QString::fromStdWString(L"/" + sName);
QString sFileQT = QFileDialog::getSaveFileName(NULL, QString(), sDocumentsPath);
std::wstring sPathQT = sFileQT.toStdWString();
m_pManager->EndSaveDialog(sPathQT);
m_sDownloadName = L"";
}
void QAscMainPanel::sendDialogSave(std::wstring sName)
{
m_sDownloadName = sName;
emit dialogSave();
}
void QAscMainPanel::resizeEvent(QResizeEvent* event)
{
this->RecalculatePlaces();
}
void QAscMainPanel::OnEvent(NSEditorApi::CAscMenuEvent* pEvent)
{
if (NULL == pEvent)
return;
switch (pEvent->m_nType)
{
case ASC_MENU_EVENT_TYPE_CEF_CREATETAB:
{
NSEditorApi::CAscCreateTab* pData = (NSEditorApi::CAscCreateTab*)pEvent->m_pData;
QString sUrl = QString::fromStdWString(pData->get_Url());
((QAscTabWidget*)m_pTabs)->OpenPopup(sUrl);
break;
}
case ASC_MENU_EVENT_TYPE_CEF_TABEDITORTYPE:
{
NSEditorApi::CAscTabEditorType* pData = (NSEditorApi::CAscTabEditorType*)pEvent->m_pData;
CCefView* pView = m_pManager->GetViewById(pData->get_Id());
if (NULL != pView && pView->GetType() == cvwtEditor)
{
CCefViewEditor* pEditor = (CCefViewEditor*)pView;
pEditor->SetEditorType((AscEditorType)pData->get_Type());
}
((QAscTabWidget*)m_pTabs)->UpdateIcons();
break;
}
case ASC_MENU_EVENT_TYPE_CEF_ONCLOSE:
{
NSEditorApi::CAscTypeId* pId = (NSEditorApi::CAscTypeId*)pEvent->m_pData;
int nId = pId->get_Id();
int nIndex = ((QAscTabWidget*)m_pTabs)->GetTabIndexById(nId);
m_pManager->DestroyCefView(nId);
if (-1 != nIndex)
m_pTabs->removeTab(nIndex);
break;
}
case ASC_MENU_EVENT_TYPE_CEF_DOWNLOAD_START:
{
NSEditorApi::CAscDownloadFileInfo* pData = (NSEditorApi::CAscDownloadFileInfo*)pEvent->m_pData;
QString sUrl = QString::fromStdWString(pData->get_Url());
((QAscTabWidget*)m_pTabs)->OpenDownload(sUrl, pData->get_Id());
break;
}
case ASC_MENU_EVENT_TYPE_CEF_DOWNLOAD:
{
NSEditorApi::CAscDownloadFileInfo* pData = (NSEditorApi::CAscDownloadFileInfo*)pEvent->m_pData;
if (pData->get_IsComplete())
{
((QAscTabWidget*)m_pTabs)->EndDownload(pData->get_Id());
}
ADDREFINTERFACE(pData);
emit downloadEvent(pData);
break;
}
case ASC_MENU_EVENT_TYPE_CEF_DOCUMENT_NAME:
{
NSEditorApi::CAscDocumentName* pData = (NSEditorApi::CAscDocumentName*)pEvent->m_pData;
QString sUrl = QString::fromStdWString(pData->get_Name());
((QAscTabWidget*)m_pTabs)->onSendNameAsync(sUrl, pData->get_Id());
break;
}
case ASC_MENU_EVENT_TYPE_CEF_MODIFY_CHANGED:
{
NSEditorApi::CAscDocumentModifyChanged* pData = (NSEditorApi::CAscDocumentModifyChanged*)pEvent->m_pData;
emit setModified(pData->get_Id(), pData->get_Changed());
break;
}
case ASC_MENU_EVENT_TYPE_CEF_ONSAVE:
{
OutputDebugStringA("onsave");
break;
}
case ASC_MENU_EVENT_TYPE_CEF_ONBEFORE_PRINT_END:
{
NSEditorApi::CAscPrintEnd* pData = (NSEditorApi::CAscPrintEnd*)pEvent->m_pData;
emit signalPrint(pData->get_Id(), pData->get_PagesCount());
break;
}
case ASC_MENU_EVENT_TYPE_CEF_ONKEYBOARDDOWN:
{
NSEditorApi::CAscKeyboardDown* pData = (NSEditorApi::CAscKeyboardDown*)pEvent->m_pData;
QString sFormat = QString("code: %1, ctrl: %2, shift: %3, alt: %4").arg(
QString::number(pData->get_KeyCode()),
QString::number((int)pData->get_IsCtrl()),
QString::number((int)pData->get_IsShift()),
QString::number((int)pData->get_IsAlt()));
std::string sOut = sFormat.toStdString();
OutputDebugStringA(sOut.c_str());
if (pData->get_KeyCode() == 32 && pData->get_IsAlt() == true)
{
RECT winrect;
HWND windowHandle = (HWND)this->parentWidget()->winId();
GetWindowRect( windowHandle, &winrect );
TrackPopupMenu( GetSystemMenu( windowHandle, false ), TPM_TOPALIGN | TPM_LEFTALIGN, winrect.left + 5, winrect.top + 5, 0, windowHandle, NULL);
}
break;
}
}
RELEASEINTERFACE(pEvent);
}
#ifndef QMAINPANEL_H
#define QMAINPANEL_H
#include <QMouseEvent>
#include <QResizeEvent>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QPushButton>
#include <QLabel>
#include "../../../lib/include/applicationmanager.h"
class QAscMainPanel : public QWidget, public NSEditorApi::CAscMenuEventListener
{
Q_OBJECT
signals:
void downloadEvent( NSEditorApi::CAscDownloadFileInfo* );
void setModified(int, bool);
void signalPrint(int, int);
void dialogSave();
public:
QAscMainPanel( QWidget *parent, CAscApplicationManager* pManager );
void resizeEvent(QResizeEvent* event);
public slots:
void pushButtonSaveClicked();
void pushButtonMainClicked();
void downloadEventSlot( NSEditorApi::CAscDownloadFileInfo* );
void onSetModified(int, bool);
void slotPrint(int, int);
void onDialogSave();
private:
QPushButton* m_pButtonMain;
QWidget* m_pMainWidget;
QPushButton* m_pButtonMinimize;
QPushButton* m_pButtonMaximize;
QPushButton* m_pButtonClose;
QPushButton* m_pSaveModifiedButton;
QTabWidget* m_pTabs;
QWidget* m_pSeparator;
std::wstring m_sDownloadName;
CAscApplicationManager* m_pManager;
std::map<int, NSEditorApi::CAscDownloadFileInfo*> m_mapDownloads;
QWidget* m_pDownloadBackground;
QLabel* m_pDownloadLable;
public:
WId GetHwndForKeyboard()
{
return ((QWidget*)m_pTabs->parent())->winId();
}
public:
virtual void OnEvent(NSEditorApi::CAscMenuEvent* pEvent);
virtual bool IsSupportEvent(int nEventType)
{
return true;
}
void sendDialogSave(std::wstring sName);
private:
void RecalculatePlaces();
};
#endif // QMAINPANEL_H
#ifndef ASCTABWIDGET
#define ASCTABWIDGET
#include <QResizeEvent>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QTabBar>
#include <QtWidgets/QPushButton>
#include <QStylePainter>
#include <QStyleOption>
#include "../../../lib/include/applicationmanager.h"
#include "../../../lib/qcefview/qcefview.h"
class QPushButtonWrapper : public QPushButton
{
Q_OBJECT
public:
QCefView* m_pView;
public:
QPushButtonWrapper(QWidget *parent = 0) : QPushButton(parent)
{
m_pView = NULL;
}
public:
virtual void paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
};
class QAscTabWidget : public QTabWidget
{
Q_OBJECT
public:
QWidget* m_pMainWidget;
QPushButton* m_pMainButton;
CAscApplicationManager* m_pManager;
std::map<int, QCefView*> m_mapDownloads;
int m_nAreaWidth;
int m_nAreaHeight;
signals:
void sendPopup( QString );
void sendDownload( QString, int );
void sendEndDownload( int );
void sendName( QString, int );
public:
QAscTabWidget(QWidget *parent = 0) : QTabWidget(parent)
{
m_nAreaWidth = -1;
m_nAreaHeight = -1;
QObject::connect(this, SIGNAL( sendPopup( QString ) ), this, SLOT( openPopup(QString) ), Qt::QueuedConnection );
QObject::connect(this, SIGNAL( sendDownload( QString , int) ), this, SLOT( openDownload(QString, int) ), Qt::QueuedConnection );
QObject::connect(this, SIGNAL( sendEndDownload( int ) ), this, SLOT( endDownload(int) ), Qt::QueuedConnection );
QObject::connect(this, SIGNAL( sendName(QString,int)), this, SLOT( onSendName(QString, int) ), Qt::QueuedConnection );
this->tabBar()->setMovable(true);
//QString strPaneColor = "#FFFFFF";
QString strPaneColor = "#313437";
QString strStyleQSS = "";
//strStyleQSS += "QTabWidget QWidget { background-color:#FFFFFF;border:none;padding:0;margin:0; }";
strStyleQSS += ("QTabWidget::pane { background-color:" + strPaneColor + "; border:none; }");
strStyleQSS += "QTabWidget::tab-bar { height: 29px; left: 111px; }";
strStyleQSS += "QTabBar::tab { \
background-color: #CFCFCF; border: 1px solid #CFCFCF; border-radius: 1px; \
min-width: 41px; max-width: 135px; \
width:135px; height: 27px; \
margin-left: 0px; margin-right: 1px; margin-top: 0px; margin-bottom: 0px; }";
strStyleQSS += "QTabBar::tab:hover { \
background-color: #DDDDDD; border: 1px solid #DDDDDD; border-radius: 1px; }";
strStyleQSS += "QTabBar::tab:selected { \
background-color: #F1F1F1; border: 1px solid #F1F1F1; border-radius: 1px;}";
strStyleQSS += "QTabBar::tab:first { margin-left: 0px; }";
strStyleQSS += "QTabBar::tab:last { }";
strStyleQSS += "QTabBar::tear { width: 0px; }";
strStyleQSS += "QTabBar QToolButton::left-arrow {margin:-2;background-color:#FFFFFF;border: 1px solid #FFFFFF; }";
strStyleQSS += "QTabBar QToolButton::left-arrow { image: url(:/Icons/changetab_left_normal.png) }";
strStyleQSS += "QTabBar QToolButton::left-arrow:hover { image: url(:/Icons/changetab_left_hover.png) }";
strStyleQSS += "QTabBar QToolButton::left-arrow:disabled { image: url(:/Icons/changetab_left_disabled.png) }";
strStyleQSS += "QTabBar QToolButton::left-arrow:pressed { image: url(:/Icons/changetab_left_active.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow {margin:-2;background-color:#FFFFFF;border: 1px solid #FFFFFF;}";
strStyleQSS += "QTabBar QToolButton::right-arrow { image: url(:/Icons/changetab_right_normal.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow:hover { image: url(:/Icons/changetab_right_hover.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow:disabled { image: url(:/Icons/changetab_right_disabled.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow:pressed { image: url(:/Icons/changetab_right_active.png) }";
strStyleQSS += "QTabBar::scroller { padding: 0px; margin: 0px;background-color:#FFFFFF;border: 1px solid #FFFFFF; width:10; }";
setStyleSheet(strStyleQSS);
QSize iconSize;
iconSize.setWidth(18);
iconSize.setHeight(10);
this->setIconSize(iconSize);
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChangedSlot(int)));
}
void addEditor(QString strName, AscEditorType etType = etDocument, std::wstring strUrl = L"")
{
if (!m_pManager)
return;
QCefView* pView = new QCefView(this);
pView->SetBackgroundCefColor(244, 244, 244);
pView->Create(m_pManager, cvwtEditor);
this->addTab(pView, strName);
this->resizeEvent(NULL);
pView->GetCefView()->load(strUrl);
QPushButtonWrapper *close = new QPushButtonWrapper(pView);
close->m_pView = pView;
QObject::connect(close, SIGNAL(clicked()), this, SLOT(clickedSlotClose()));
QString sStyleClose = "QPushButton {background:transparent;background-repeat: no-repeat;background-image:url(:/Icons/output_tab_normal.png);border:none;width:8px;height:11px;margin-right:5px;} ";
sStyleClose += "QPushButton:hover {background-image:url(:/Icons/output_tab_hover.png);border:none;width:8px;height:11px;margin-right:5px;}";
sStyleClose += "QPushButton:pressed {background-image:url(:/Icons/output_tab_active.png);border:none;width:8px;height:11px;margin-right:5px;}";
close->setStyleSheet(sStyleClose);
this->tabBar()->setTabButton(this->tabBar()->count() - 1, QTabBar::RightSide, close);
this->resizeEvent(NULL);
}
protected:
void resizeEvent(QResizeEvent* e)
{
Q_UNUSED(e);
int nMin = 41;
int nMax = 135;
int nFirst = 44;
int nStartOffset = 5;
int nBetweenApp = 5;
int nButtonW = 16;
int nEndOffset = 40;
int nControlWidth = this->width();
int nTabBarWidth = nControlWidth - nFirst - nStartOffset - nEndOffset - 3 * nButtonW - 2 * nBetweenApp;
int nCountTabs = this->tabBar()->count();
if (nCountTabs == 0)
nCountTabs = 1;
int nTabWidth = (nTabBarWidth - (2 + 2) * nCountTabs) / nCountTabs;
if (nTabWidth > nMax)
nTabWidth = nMax;
if (nTabWidth < nMin)
nTabWidth = nMin;
int nMinTabBarWidth = (nTabWidth + 2 + 2) * nCountTabs;
if (nTabBarWidth > nMinTabBarWidth)
nTabBarWidth = nMinTabBarWidth;
//QString strPaneColor = "#FFFFFF";
QString strPaneColor = "#313437";
QString strStyleQSS = "";
//strStyleQSS += "QTabWidget QWidget { background-color:#FFFFFF;border:none;padding:0;margin:0; }";
strStyleQSS += ("QTabWidget::pane { background-color:" + strPaneColor + "; border: none; }");
strStyleQSS += QString("QTabWidget::tab-bar { width:%1px; height: 29px; left: 111px; }").arg(nTabBarWidth);
strStyleQSS += QString("QTabBar::tab { \
background-color: #CFCFCF; border: 1px solid #CFCFCF; border-radius: 1px; \
min-width: 41px; max-width: 135px; \
width:%1px; height: 27px; \
margin-right: 1px; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; }").arg(nTabWidth);
strStyleQSS += "QTabBar::tab:hover { \
background-color: #DDDDDD; border: 1px solid #DDDDDD; border-radius: 1px; }";
strStyleQSS += "QTabBar::tab:selected { \
background-color: #F1F1F1; border: 1px solid #F1F1F1; border-radius: 1px;}";
strStyleQSS += "QTabBar::tab:first { margin-left: 0px; }";
strStyleQSS += "QTabBar::tab:last { }";
strStyleQSS += "QTabBar::tear { width: 0px; }";
strStyleQSS += "QTabBar QToolButton::left-arrow {margin:-2;background-color:#FFFFFF;border: 1px solid #FFFFFF; }";
strStyleQSS += "QTabBar QToolButton::left-arrow { image: url(:/Icons/changetab_left_normal.png) }";
strStyleQSS += "QTabBar QToolButton::left-arrow:hover { image: url(:/Icons/changetab_left_hover.png) }";
strStyleQSS += "QTabBar QToolButton::left-arrow:disabled { image: url(:/Icons/changetab_left_disabled.png) }";
strStyleQSS += "QTabBar QToolButton::left-arrow:pressed { image: url(:/Icons/changetab_left_active.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow {margin:-2;background-color:#FFFFFF;border: 1px solid #FFFFFF;}";
strStyleQSS += "QTabBar QToolButton::right-arrow { image: url(:/Icons/changetab_right_normal.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow:hover { image: url(:/Icons/changetab_right_hover.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow:disabled { image: url(:/Icons/changetab_right_disabled.png) }";
strStyleQSS += "QTabBar QToolButton::right-arrow:pressed { image: url(:/Icons/changetab_right_active.png) }";
strStyleQSS += "QTabBar::scroller { padding: 0px; margin: 0px;background-color:#FFFFFF;border: 1px solid #FFFFFF; width:10; }";
strStyleQSS += "QTabBar QIcon { offset: 10px; }";
strStyleQSS += "QTabBar::tab:text{ font:Arial;font-weight:normal;font-size:8pt;text-align:left;}";
setStyleSheet(strStyleQSS);
int nNewAreaWidth = width();
int nNewAreaHeight = height() - this->tabBar()->height();
if (nNewAreaWidth != m_nAreaWidth || nNewAreaHeight != m_nAreaHeight)
{
m_nAreaWidth = nNewAreaWidth;
m_nAreaHeight = nNewAreaHeight;
int nCountNatural = this->count();
for (int i = 0; i < nCountNatural; ++i)
{
if (i == this->currentIndex())
continue;
((QCefView*)widget(i))->GetCefView()->resizeEvent(m_nAreaWidth, m_nAreaHeight);
}
}
}
public:
void OpenPopup(QString strUrl)
{
if (strUrl.length() == 0)
return;
emit sendPopup(strUrl);
}
void OpenDownload(QString strUrl, int nParentId)
{
if (strUrl.length() == 0)
return;
emit sendDownload(strUrl, nParentId);
}
void EndDownload(int nId)
{
emit sendEndDownload(nId);
}
public slots:
void currentChangedSlot(int index)
{
resizeEvent(NULL);
if (!m_pMainWidget->isHidden())
{
m_pMainWidget->setHidden(true);
m_pMainButton->setStyleSheet("QPushButton {background-image:url(:/Icons/Documents_disabled_normal.png);border:none;margin:0;padding:0;}\
QPushButton::hover {background-image:url(:/Icons/Documents_disabled_normal.png);border:none;margin:0;padding:0;}\
QPushButton::pressed {background-image:url(:/Icons/Documents_disabled_hover.png);border:none;margin:0;padding:0;}");
}
FireFocus(index);
UpdateIcons();
}
void openPopup(QString sValue)
{
this->addEditor("Editor", etDocument, sValue.toStdWString());
}
void openDownload(QString sUrl, int nParentId)
{
std::wstring strUrl = sUrl.toStdWString();
if (!m_pManager)
return;
QCefView* pView = new QCefView(NULL);
pView->Create(m_pManager, cvwtEditor);
pView->GetCefView()->SetParentCef(nParentId);
pView->GetCefView()->load(strUrl);
m_mapDownloads.insert(std::pair<int, QCefView*>(pView->GetCefView()->GetId(), pView));
}
void endDownload(int nId)
{
std::map<int, QCefView*>::iterator i = m_mapDownloads.find(nId);
if (i != m_mapDownloads.end())
{
QCefView* pView = i->second;
RELEASEOBJECT(pView);
m_mapDownloads.erase(i);
}
}
void onSendNameAsync(QString sUrl, int nId)
{
emit sendName(sUrl, nId);
}
void onSendName(QString sUrl, int nId)
{
int nIndex = this->GetTabIndexById(nId);
this->tabBar()->setTabText(nIndex, sUrl);
}
void FireFocus(int index = -1)
{
int nIndex = (index >= 0) ? index : this->currentIndex();
if (nIndex >= 0)
((QCefView*)this->widget(nIndex))->GetCefView()->focus();
}
void UpdateIcons()
{
QTabBar* pBar = this->tabBar();
int nCount = pBar->count();
int nSelectedIndex = pBar->currentIndex();
for (int i = 0; i < nCount; ++i)
{
CCefViewEditor* pEditor = (CCefViewEditor*)(((QCefView*)(this->widget(i)))->GetCefView());
bool bIsActive = (i == nSelectedIndex) ? true : false;
switch (pEditor->GetEditorType())
{
case etPresentation:
{
pBar->setTabIcon(i, bIsActive ? QIcon(":/Icons/tabicon_PE_active.png") : QIcon(":/Icons/tabicon_PE_normal.png"));
break;
}
case etSpreadsheet:
{
pBar->setTabIcon(i, bIsActive ? QIcon(":/Icons/tabicon_SE_active.png") : QIcon(":/Icons/tabicon_SE_normal.png"));
break;
}
case etDocument:
default:
{
pBar->setTabIcon(i, bIsActive ? QIcon(":/Icons/tabicon_DE_active.png") : QIcon(":/Icons/tabicon_DE_normal.png"));
break;
}
}
//pBar->setTabTextColor(nIndex, bIsActive ? QColor(255, 255, 255) : QColor(51, 51, 51));
pBar->setTabTextColor(i, QColor(51, 51, 51));
}
}
public slots:
void clickedSlotClose()
{
QPushButtonWrapper* pButton = (QPushButtonWrapper*)sender();
QCefView* pViewCef = pButton->m_pView;
int nId = pViewCef->GetCefView()->GetId();
#if 1
std::string sId = std::to_string(nId);sId += "\n";
OutputDebugStringA(sId.c_str());
#endif
NSEditorApi::CAscMenuEvent* pEvent = new NSEditorApi::CAscMenuEvent();
pEvent->m_nType = ASC_MENU_EVENT_TYPE_CEF_CLOSE;
pViewCef->GetCefView()->Apply(pEvent);
}
int GetTabIndexById(int nId)
{
QTabBar* pBar = this->tabBar();
int nCount = pBar->count();
for (int i = 0; i < nCount; ++i)
{
CCefView* pEditor = (CCefView*)(((QCefView*)(this->widget(i)))->GetCefView());
if (pEditor->GetId() == nId)
return i;
}
return -1;
}
};
#endif // ASCTABWIDGET
#include "QAscMain.h"
int main( int argc, char *argv[] )
{
return AscEditor_Main(argc, argv);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment