⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platform.cpp

📁 porting scintilla to qt
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return metrics(font_).leading();}int SurfaceImpl::Height(Font &font_){    return metrics(font_).height();}void SurfaceImpl::SetClip(PRectangle rc){    Q_ASSERT(painter);    painter->setClipRect(rc.left, rc.top, rc.right - rc.left,            rc.bottom - rc.top);}void SurfaceImpl::FlushCachedState(){}// Get the metrics for a font.QFontMetrics SurfaceImpl::metrics(Font &font_){    QFont *f = PFont(font_.GetID()), fnt;    if (f)        fnt = *f;    else        fnt = QApplication::font();    return QFontMetrics(fnt, pd);}// Convert a Scintilla string to a Qt Unicode string.QString SurfaceImpl::convertText(const char *s, int len){    if (unicodeMode)        return QString::fromUtf8(s, len);    return QString::fromLatin1(s, len);}// Convert a Scintilla colour and alpha component to a Qt QRgb.QRgb SurfaceImpl::convertQRgb(const ColourAllocated &col, unsigned alpha){    long c = col.AsLong();    unsigned r = c & 0xff;    unsigned g = (c >> 8) & 0xff;    unsigned b = (c >> 16) & 0xff;    QRgb rgba = (alpha << 24) | (r << 16) | (g << 8) | b;    return rgba;}// Convert a Scintilla colour, and optional alpha component, to a Qt QColor.QColor SurfaceImpl::convertQColor(const ColourAllocated &col, unsigned alpha){    return QColor(convertQRgb(col, alpha));}// Window (widget) management.Window::~Window(){}void Window::Destroy(){    QWidget *w = PWindow(id);    if (w)    {        // Delete the widget next time round the event loop rather than        // straight away.  This gets round a problem when auto-completion lists        // are cancelled after an entry has been double-clicked, ie. the list's        // dtor is called from one of the list's slots.  There are other ways        // around the problem but this is the simplest and doesn't seem to        // cause problems of its own.        w->deleteLater();        id = 0;    }}bool Window::HasFocus(){    return PWindow(id)->hasFocus();}PRectangle Window::GetPosition(){    QWidget *w = PWindow(id);    // Before any size allocated pretend its big enough not to be scrolled.    PRectangle rc(0,0,5000,5000);    if (w)    {        const QRect &r = w->geometry();        rc.right = r.right() - r.left() + 1;        rc.bottom = r.bottom() - r.top() + 1;    }    return rc;}void Window::SetPosition(PRectangle rc){    PWindow(id)->setGeometry(rc.left, rc.top, rc.right - rc.left,            rc.bottom - rc.top);}void Window::SetPositionRelative(PRectangle rc, Window relativeTo){    QWidget *rel = PWindow(relativeTo.id);    QPoint pos = rel->mapToGlobal(rel->pos());    int x = pos.x() + rc.left;    int y = pos.y() + rc.top;    PWindow(id)->setGeometry(x, y, rc.right - rc.left, rc.bottom - rc.top);}PRectangle Window::GetClientPosition(){    return GetPosition();}void Window::Show(bool show){    QWidget *w = PWindow(id);    if (show)        w->show();    else        w->hide();}void Window::InvalidateAll(){    QWidget *w = PWindow(id);    if (w)        w->update();}void Window::InvalidateRectangle(PRectangle rc){    QWidget *w = PWindow(id);    if (w)        w->update(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);}void Window::SetFont(Font &font){    PWindow(id)->setFont(*PFont(font.GetID()));}void Window::SetCursor(Cursor curs){    Qt::CursorShape qc;    switch (curs)    {    case cursorText:        qc = Qt::IBeamCursor;        break;    case cursorUp:        qc = Qt::UpArrowCursor;        break;    case cursorWait:        qc = Qt::WaitCursor;        break;    case cursorHoriz:        qc = Qt::SizeHorCursor;        break;    case cursorVert:        qc = Qt::SizeVerCursor;        break;    case cursorHand:        qc = Qt::PointingHandCursor;        break;    default:        qc = Qt::ArrowCursor;    }    PWindow(id)->setCursor(qc);}void Window::SetTitle(const char *s){    PWindow(id)->setWindowTitle(s);}// Menu managementMenu::Menu() : id(0){}void Menu::CreatePopUp(){	Destroy();	id = new QStePopup();}void Menu::Destroy(){	QStePopup *m = PMenu(id);	if(m){		delete m;		id = 0;	}}void Menu::Show(Point pt,Window &wid){	PMenu(id)->popup(QPoint(pt.x,pt.y));}class DynamicLibraryImpl : public DynamicLibrary{public:	DynamicLibraryImpl(const char *modulePath){		m = new QLibrary(modulePath);		m->load();	}	virtual ~DynamicLibraryImpl(){		if(m)			delete m;	}	virtual Function FindFunction(const char *name){		if(m)			return m->resolve(name);		return 0;	}	virtual bool IsValid(){		return m && m->isLoaded();	}private:	QLibrary *m;};DynamicLibrary *DynamicLibrary::Load(const char *modulePath){	return new DynamicLibraryImpl(modulePath);}// Elapsed time.  This implementation assumes that the maximum elapsed time is// less than 48 hours.ElapsedTime::ElapsedTime(){	QTime now = QTime::currentTime();	bigBit = now.hour() * 60 * 60 + now.minute() * 60 + now.second();	littleBit = now.msec();}double ElapsedTime::Duration(bool reset){	long endBigBit,endLittleBit;	QTime now = QTime::currentTime();	endBigBit = now.hour() * 60 * 60 + now.minute() * 60 + now.second();	endLittleBit = now.msec();	double duration = endBigBit - bigBit;	if(duration < 0 || (duration == 0 && endLittleBit < littleBit))		duration += 24 * 60 * 60;	duration += (endLittleBit - littleBit)/1000.0;	if(reset){		bigBit = endBigBit;		littleBit = endLittleBit;	}	return duration;}//Manage system wide parameters.ColourDesired Platform::Chrome(){	return ColourDesired(0xe0,0xe0,0xe0);}ColourDesired Platform::ChromeHighlight(){	return ColourDesired(0xff,0xff,0xff);}const char *Platform::DefaultFont(){	static QByteArray def_font;	def_font = QApplication::font().family().toAscii();	return def_font.constData();}int Platform::DefaultFontSize(){	return QApplication::font().pointSize();}unsigned int Platform::DoubleClickTime(){	return QApplication::doubleClickInterval();}bool Platform::MouseButtonBounce(){	return true;}void Platform::DebugDisplay(const char *s){	qDebug("%s",s);}bool Platform::IsKeyDown(int){	return false;}long Platform::SendScintilla(WindowID w,unsigned int msg,unsigned long wParam,long lParam){	return static_cast<QSteScintillaBase *>(PWindow(w)->parentWidget())->sendMsgToSci(msg,wParam,lParam);}long Platform::SendScintillaPointer(WindowID w,unsigned int msg,unsigned long wParam,void *lParam){	return static_cast<QSteScintillaBase *>(PWindow(w)->parentWidget())->sendMsgToSci(msg,wParam,reinterpret_cast<long>(lParam));}bool Platform::IsDBCSLeadByte(int,char){    // We don't support DBCS.    return false;}int Platform::DBCSCharLength(int, const char *){    // We don't support DBCS.    return 1;}int Platform::DBCSCharMaxLength(){    // We don't support DBCS.    return 2;}int Platform::Minimum(int a, int b){    return (a < b) ? a : b;}int Platform::Maximum(int a, int b){    return (a > b) ? a : b;}int Platform::Clamp(int val, int minVal, int maxVal){    if (val > maxVal)        val = maxVal;    if (val < minVal)        val = minVal;    return val;}//#define TRACE#ifdef TRACEvoid Platform::DebugPrintf(const char *format, ...){    char buffer[2000];    va_list pArguments;    va_start(pArguments, format);    vsprintf(buffer, format, pArguments);    va_end(pArguments);    DebugDisplay(buffer);}#elsevoid Platform::DebugPrintf(const char *, ...){}#endifstatic bool assertionPopUps = true;bool Platform::ShowAssertionPopUps(bool assertionPopUps_){    bool ret = assertionPopUps;    assertionPopUps = assertionPopUps_;    return ret;}void Platform::Assert(const char *c, const char *file, int line){    qFatal("Assertion [%s] failed at %s %d\n", c, file, line);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -