forked from organicmaps/organicmaps
First version of guide page.
Need to check for sl::Str function policies.
This commit is contained in:
parent
bfe564056e
commit
6bc7acd8e2
5 changed files with 185 additions and 13 deletions
99
qt/guide_page.cpp
Normal file
99
qt/guide_page.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include "guide_page.hpp"
|
||||
|
||||
#include "../platform/platform.hpp"
|
||||
|
||||
#include "../coding/strutil.hpp"
|
||||
|
||||
#include <QtWebKit/QWebView>
|
||||
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
|
||||
|
||||
namespace qt {
|
||||
|
||||
GuidePageHolder::GuidePageHolder(QWidget * pParent)
|
||||
: base_type(pParent)
|
||||
{
|
||||
QVBoxLayout * pLayout = new QVBoxLayout(this);
|
||||
pLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_pEditor = new QLineEdit(this);
|
||||
|
||||
m_pView = new QWebView(this);
|
||||
|
||||
connect(m_pEditor, SIGNAL(returnPressed()), this, SLOT(OnShowPage()));
|
||||
|
||||
pLayout->addWidget(m_pEditor);
|
||||
pLayout->addWidget(m_pView);
|
||||
setLayout(pLayout);
|
||||
|
||||
CreateEngine();
|
||||
}
|
||||
|
||||
void GuidePageHolder::showEvent(QShowEvent * e)
|
||||
{
|
||||
base_type::showEvent(e);
|
||||
|
||||
m_pEditor->setFocus();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
sl::StrFn::Str const * StrCreate(char const * pUtf8Data, uint32_t sz)
|
||||
{
|
||||
wstring * s = new wstring();
|
||||
*s = FromUtf8(string(pUtf8Data));
|
||||
return reinterpret_cast<sl::StrFn::Str const *>(s);
|
||||
}
|
||||
|
||||
void StrDestroy(sl::StrFn::Str const * p)
|
||||
{
|
||||
delete reinterpret_cast<wstring const *>(p);
|
||||
}
|
||||
|
||||
int StrPrimaryCompare(void *, sl::StrFn::Str const * a, sl::StrFn::Str const * b)
|
||||
{
|
||||
wstring const * pA = reinterpret_cast<wstring const *>(a);
|
||||
wstring const * pB = reinterpret_cast<wstring const *>(b);
|
||||
return *pA == *pB;
|
||||
}
|
||||
|
||||
int StrSecondaryCompare(void *, sl::StrFn::Str const * a, sl::StrFn::Str const * b)
|
||||
{
|
||||
wstring const * pA = reinterpret_cast<wstring const *>(a);
|
||||
wstring const * pB = reinterpret_cast<wstring const *>(b);
|
||||
return *pA == *pB;
|
||||
}
|
||||
}
|
||||
|
||||
void GuidePageHolder::CreateEngine()
|
||||
{
|
||||
string const dicPath = GetPlatform().ReadPathForFile("dictionary.slf");
|
||||
string const indPath = GetPlatform().WritableDir() + "index";
|
||||
|
||||
sl::StrFn fn;
|
||||
fn.Create = &StrCreate;
|
||||
fn.Destroy = &StrDestroy;
|
||||
fn.PrimaryCompare = &StrPrimaryCompare;
|
||||
fn.SecondaryCompare = &StrSecondaryCompare;
|
||||
|
||||
fn.m_pData = 0;
|
||||
fn.m_PrimaryCompareId = 1;
|
||||
fn.m_SecondaryCompareId = 2;
|
||||
|
||||
m_pEngine.reset(new sl::SloynikEngine(dicPath, indPath, fn));
|
||||
}
|
||||
|
||||
void GuidePageHolder::OnShowPage()
|
||||
{
|
||||
sl::SloynikEngine::SearchResult res;
|
||||
m_pEngine->Search(m_pEditor->text().toStdString(), res);
|
||||
|
||||
sl::SloynikEngine::ArticleData data;
|
||||
m_pEngine->GetArticleData(res.m_FirstMatched, data);
|
||||
|
||||
m_pView->setHtml(QString::fromUtf8(data.m_HTML.c_str()));
|
||||
}
|
||||
|
||||
}
|
40
qt/guide_page.hpp
Normal file
40
qt/guide_page.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include "../words/sloynik_engine.hpp"
|
||||
|
||||
#include "../std/scoped_ptr.hpp"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
|
||||
class QLineEdit;
|
||||
class QWebView;
|
||||
|
||||
namespace sl { class SloynikEngine; }
|
||||
|
||||
namespace qt
|
||||
{
|
||||
class GuidePageHolder : public QWidget
|
||||
{
|
||||
typedef QWidget base_type;
|
||||
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
GuidePageHolder(QWidget * pParent);
|
||||
|
||||
protected:
|
||||
void CreateEngine();
|
||||
|
||||
virtual void showEvent(QShowEvent * e);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void OnShowPage();
|
||||
|
||||
private:
|
||||
QLineEdit * m_pEditor;
|
||||
QWebView * m_pView;
|
||||
|
||||
scoped_ptr<sl::SloynikEngine> m_pEngine;
|
||||
};
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
#include "about.hpp"
|
||||
#include "preferences_dialog.hpp"
|
||||
#include "info_dialog.hpp"
|
||||
#include "guide_page.hpp"
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
|
@ -21,6 +22,7 @@
|
|||
#include <QtGui/QAction>
|
||||
#include <QtGui/QMenuBar>
|
||||
#include <QtGui/QMenu>
|
||||
|
||||
#include <QtCore/QFile>
|
||||
|
||||
#include "../base/start_mem_debug.hpp"
|
||||
|
@ -38,6 +40,7 @@ MainWindow::MainWindow() : m_updateDialog(0)
|
|||
CreateNavigationBar();
|
||||
|
||||
CreateClassifPanel();
|
||||
CreateGuidePanel();
|
||||
|
||||
setCentralWidget(m_pDrawWidget);
|
||||
|
||||
|
@ -160,22 +163,39 @@ void MainWindow::LoadState()
|
|||
|
||||
void MainWindow::CreateClassifPanel()
|
||||
{
|
||||
m_pClassifDock = new QDockWidget(tr("Classificator Bar"), this);
|
||||
CreatePanelImpl(0, tr("Classificator Bar"),
|
||||
QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), SLOT(ShowClassifPanel()));
|
||||
|
||||
ClassifTreeHolder * pCTree = new ClassifTreeHolder(m_pClassifDock, m_pDrawWidget, SLOT(Repaint()));
|
||||
ClassifTreeHolder * pCTree = new ClassifTreeHolder(m_Docks[0], m_pDrawWidget, SLOT(Repaint()));
|
||||
pCTree->SetRoot(classif().GetMutableRoot());
|
||||
|
||||
m_pClassifDock->setWidget(pCTree);
|
||||
m_Docks[0]->setWidget(pCTree);
|
||||
}
|
||||
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_pClassifDock);
|
||||
void MainWindow::CreateGuidePanel()
|
||||
{
|
||||
CreatePanelImpl(1, tr("Guide Bar"),
|
||||
QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G), SLOT(ShowGuidePanel()));
|
||||
|
||||
qt::GuidePageHolder * pGPage = new qt::GuidePageHolder(m_Docks[1]);
|
||||
|
||||
m_Docks[1]->setWidget(pGPage);
|
||||
}
|
||||
|
||||
void MainWindow::CreatePanelImpl(size_t i, QString const & name,
|
||||
QKeySequence const & hotkey, char const * slot)
|
||||
{
|
||||
m_Docks[i] = new QDockWidget(name, this);
|
||||
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_Docks[i]);
|
||||
|
||||
// hide by default
|
||||
m_pClassifDock->hide();
|
||||
m_Docks[i]->hide();
|
||||
|
||||
// register a hotkey to show classificator panel
|
||||
QAction * pAct = new QAction(this);
|
||||
pAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
|
||||
connect(pAct, SIGNAL(triggered()), this, SLOT(ShowClassifPanel()));
|
||||
pAct->setShortcut(hotkey);
|
||||
connect(pAct, SIGNAL(triggered()), this, slot);
|
||||
addAction(pAct);
|
||||
}
|
||||
|
||||
|
@ -283,7 +303,12 @@ void MainWindow::ShowUpdateDialog()
|
|||
|
||||
void MainWindow::ShowClassifPanel()
|
||||
{
|
||||
m_pClassifDock->show();
|
||||
m_Docks[0]->show();
|
||||
}
|
||||
|
||||
void MainWindow::ShowGuidePanel()
|
||||
{
|
||||
m_Docks[1]->show();
|
||||
}
|
||||
|
||||
void MainWindow::OnAbout()
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace qt
|
|||
class MainWindow : public QMainWindow
|
||||
{
|
||||
DrawWidget * m_pDrawWidget;
|
||||
QDockWidget * m_pClassifDock;
|
||||
QDockWidget * m_Docks[2];
|
||||
//FindTableWnd * m_pFindTable;
|
||||
UpdateDialog * m_updateDialog;
|
||||
|
||||
|
@ -35,7 +35,12 @@ namespace qt
|
|||
void LoadState();
|
||||
|
||||
protected:
|
||||
void CreatePanelImpl(size_t i, QString const & name, QKeySequence const & hotkey,
|
||||
char const * slot);
|
||||
|
||||
void CreateClassifPanel();
|
||||
void CreateGuidePanel();
|
||||
|
||||
void CreateNavigationBar();
|
||||
//void CreateFindTable(QLayout * pLayout);
|
||||
#if defined(Q_WS_WIN)
|
||||
|
@ -48,6 +53,7 @@ namespace qt
|
|||
//void OnFeatureClicked(int row, int col);
|
||||
void ShowUpdateDialog();
|
||||
void ShowClassifPanel();
|
||||
void ShowGuidePanel();
|
||||
void OnAbout();
|
||||
void OnPreferences();
|
||||
};
|
||||
|
|
10
qt/qt.pro
10
qt/qt.pro
|
@ -1,13 +1,13 @@
|
|||
# Main application in qt.
|
||||
ROOT_DIR = ..
|
||||
DEPENDENCIES = map storage indexer yg platform geometry coding base freetype expat fribidi tomcrypt version
|
||||
DEPENDENCIES = words map storage indexer yg platform geometry coding base bzip2 freetype expat fribidi tomcrypt version
|
||||
|
||||
include($$ROOT_DIR/common.pri)
|
||||
|
||||
TARGET = MapsWithMe
|
||||
TEMPLATE = app
|
||||
|
||||
QT *= core gui opengl network
|
||||
QT *= core gui opengl network webkit
|
||||
|
||||
win32 {
|
||||
LIBS += -lopengl32 -lws2_32 -lshell32
|
||||
|
@ -82,7 +82,8 @@ SOURCES += \
|
|||
slider_ctrl.cpp \
|
||||
about.cpp \
|
||||
preferences_dialog.cpp \
|
||||
info_dialog.cpp
|
||||
info_dialog.cpp \
|
||||
guide_page.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.hpp \
|
||||
|
@ -96,6 +97,7 @@ HEADERS += \
|
|||
slider_ctrl.hpp \
|
||||
about.hpp \
|
||||
preferences_dialog.hpp \
|
||||
info_dialog.hpp
|
||||
info_dialog.hpp \
|
||||
guide_page.hpp
|
||||
|
||||
RESOURCES += res/resources.qrc \
|
||||
|
|
Loading…
Add table
Reference in a new issue