📄 kwqtextedit.cpp
字号:
/*
* Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
* Portions Copyright (c) 2005 Nokia Corporation, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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.
*/
#include "KWQTextEdit.h"
#include "WebCoreFormControlFactory.h"
QTextEdit::QTextEdit(QWidget *parent)
: _clicked(this, SIGNAL(clicked()))
, _textChanged(this, SIGNAL(textChanged()))
{
TInputType inputType (ETextArea);
_textWidget = TWebCoreFormControlFactory::Factory()->ConstructText(inputType );
if (_textWidget)
{
_textWidget->SetEventHandler(this);
setView(_textWidget);
}
}
QTextEdit::~QTextEdit()
{
if (_textWidget)
{
_textWidget->Close();
}
}
void QTextEdit::setText(const QString &string)
{
if (_textWidget)
{
_textWidget->SetText(string.Des());
}
}
QString QTextEdit::text() const
{
if (_textWidget)
{
return QString::FromDes(_textWidget->Text());
}
return QString();
}
QString QTextEdit::textWithHardLineBreaks() const
{
return text();
}
void QTextEdit::getCursorPosition(int *paragraph, int *index) const
{
// ### NOT IMPLEMENTED
}
void QTextEdit::setCursorPosition(int paragraph, int index)
{
// ### NOT IMPLEMENTED
}
QTextEdit::WrapStyle QTextEdit::wordWrap() const
{
// by default text is wrapped to the widget wdith
return WidgetWidth;
}
void QTextEdit::setWordWrap(WrapStyle style)
{
// ### NOT IMPLEMENTED - by default text is wrapped to the widget wdith
}
void QTextEdit::setScrollBarModes(ScrollBarMode hMode, ScrollBarMode vMode)
{
// ### NOT IMPLEMENTED scrollbar modes
/*KWQTextArea *textView = (KWQTextArea *)getView();
KWQ_BLOCK_EXCEPTIONS;
// this declaration must be inside the KWQ_BLOCK_EXCEPTIONS block or the deployment build fails
bool autohides = hMode == Auto || vMode == Auto;
ASSERT(!autohides || hMode != AlwaysOn);
ASSERT(!autohides || vMode != AlwaysOn);
[textView setHasHorizontalScroller:hMode != AlwaysOff];
[textView setHasVerticalScroller:vMode != AlwaysOff];
[textView setAutohidesScrollers:autohides];
KWQ_UNBLOCK_EXCEPTIONS;*/
}
bool QTextEdit::isReadOnly() const
{
if (_textWidget)
{
return _textWidget->IsReadOnly();
}
return false;
}
void QTextEdit::setReadOnly(bool flag)
{
if (_textWidget)
{
_textWidget->SetReadOnly(flag);
}
}
bool QTextEdit::isDisabled() const
{
if (_textWidget)
{
return _textWidget->IsDisabled();
}
return false;
}
void QTextEdit::setDisabled(bool flag)
{
if (_textWidget)
{
_textWidget->SetDisabled(flag);
}
}
void QTextEdit::selectAll()
{
// ### NOT IMPLEMENTED - to check if we need implementation
}
void QTextEdit::setFont(const QFont &font)
{
QWidget::setFont(font);
if (_textWidget)
{
QFont fontCpy = font;
CFont* symFont = const_cast<CFont*>(fontCpy.Font());
_textWidget->SetFont(symFont );
}
}
bool QTextEdit::isActive() const
{
if (_textWidget)
{
return _textWidget->IsActive();
}
return false;
}
void QTextEdit::deActivate(bool acceptChanges)
{
if (_textWidget)
{
_textWidget->DeActivate(acceptChanges);
}
}
void QTextEdit::clicked()
{
_clicked.call();
}
void QTextEdit::setAlignment(AlignmentFlags alignment)
{
/*
KWQ_BLOCK_EXCEPTIONS;
KWQTextArea *textArea = getView();
[textArea setAlignment:KWQNSTextAlignmentForAlignmentFlags(alignment)];
KWQ_UNBLOCK_EXCEPTIONS;
*/
}
void QTextEdit::setWritingDirection(QPainter::TextDirection direction)
{
/*
KWQ_BLOCK_EXCEPTIONS;
KWQTextArea *textArea = getView();
[textArea setBaseWritingDirection:(direction == QPainter::RTL ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight)];
KWQ_UNBLOCK_EXCEPTIONS;
*/
}
QSize QTextEdit::sizeWithColumnsAndRows(int numColumns, int numRows) const
{
if (_textWidget)
{
_textWidget->SetSize(numColumns);
_textWidget->SetHeight(numRows);
return QSize(_textWidget->SizeForCharacterWidth(numColumns));
}
return QSize(0,0);
}
QRect QTextEdit::frameGeometry() const
{
if(_textWidget)
{
return QRect(_textWidget->Rect());
}
return QRect();
}
void QTextEdit::setFrameGeometry(const QRect &r)
{
if(_textWidget)
{
_textWidget->SetRect(r.Rect());
}
}
QWidget::FocusPolicy QTextEdit::focusPolicy() const
{
return TabFocus;
}
bool QTextEdit::checksDescendantsForFocus() const
{
return true;
}
void QTextEdit::setPalette(const QPalette &palette)
{
QWidget::setPalette(palette);
/*KWQTextArea *textArea = getView();
KWQ_BLOCK_EXCEPTIONS;
// Below is a workaround for the following AppKit bug which causes transparent backgrounds to be
// drawn opaque <rdar://problem/3142730>. Without this workaround, some textareas would be drawn with black backgrounds
// as described in <rdar://problem/3854383>. We now call setDrawsBackground:NO when the background color is completely
// transparent. This does not solve the problem for translucent background colors for textareas <rdar://problem/3865161>.
[textArea setTextColor:palette.foreground().getNSColor()];
QColor background = palette.background();
if (!background.isValid())
background = Qt::white;
[textArea setBackgroundColor:background.getNSColor()];
[textArea setDrawsBackground:background.alpha() != 0];
KWQ_UNBLOCK_EXCEPTIONS;*/
}
void QTextEdit::paint(QPainter *aPainter, const QRect& aRect)
{
TRect rect = aRect.Rect();
if (_textWidget)
{
_textWidget->Draw(aPainter->Gc(), rect);
}
}
void QTextEdit::HandleEvent(TEvent aEvent)
{
if(aEvent == EValueChanged)
{
textChanged();
}
else if (aEvent == EFocusOut && eventFilterObject())
{
QFocusEvent event(QEvent::FocusOut);
const_cast<QObject *>(eventFilterObject())->eventFilter(this, &event);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -