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

📄 kwqlineedit.cpp

📁 手机浏览器源码程序,功能强大
💻 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 "KWQButton.h"
#include "KWQLineEdit.h"

#include "KWQLogging.h"
#include "WebCoreFormControlFactory.h"

QLineEdit::QLineEdit(Type type)
    : m_returnPressed(this, SIGNAL(returnPressed()))
    , m_textChanged(this, SIGNAL(textChanged(const QString &)))
    , m_clicked(this, SIGNAL(clicked()))
    , m_performSearch(this, SIGNAL(performSearch()))
    , m_type(type)

{
	TInputType inputType  = ENormal;
	if (type == Search)
		inputType  = ESearch;
	else if (type == Password)
		inputType  = EPassword;

	m_inputWidget = TWebCoreFormControlFactory::Factory()->ConstructText(inputType );
	if (m_inputWidget)
	{
		m_inputWidget->SetEventHandler(this);
		setView(m_inputWidget);
	}
}

QLineEdit::~QLineEdit()
{
	if (m_inputWidget)
	{
		m_inputWidget->Close();
	}
}

void QLineEdit::setCursorPosition(int)
{
    // Don't do anything here.
}

int QLineEdit::cursorPosition() const
{
    // Not needed.  We ignore setCursorPosition().
    return 0;
}

void QLineEdit::setFont(const QFont &font)
{
	QWidget::setFont(font);
	if (m_inputWidget)
	{
		QFont fontCpy = font;
		CFont* symFont = const_cast<CFont*>(fontCpy.Font());
		m_inputWidget->SetFont(symFont );
	}
}

void QLineEdit::setPalette(const QPalette &palette)
{
    QWidget::setPalette(palette);

/*    NSTextField *textField = (NSTextField *)getView();

    KWQ_BLOCK_EXCEPTIONS;

    // Below we've added a special case that maps any completely transparent color to white.  This is a workaround for the following
    // AppKit problems: <rdar://problem/3142730> and <rdar://problem/3036580>.  Without this special case we have black
    // backgrounds on some text fields as described in <rdar://problem/3854383>.  Text fields will still not be able to display
    // transparent and translucent backgrounds, which will need to be fixed in the future.  See  <rdar://problem/3865114>.

    [textField setTextColor:palette.foreground().getNSColor()];

    QColor background = palette.background();
    if (!background.isValid() || background.alpha() == 0)
        background = Qt::white;
    [textField setBackgroundColor:background.getNSColor()];

    KWQ_UNBLOCK_EXCEPTIONS;*/
}

void QLineEdit::setText(const QString &s)
{
	if (m_inputWidget)
	{
		m_inputWidget->SetText(s.Des());
	}
}

QString QLineEdit::text() const
{
	if (m_inputWidget)
	{
		return QString::FromDes(m_inputWidget->Text());
	}
	return QString();
}

void QLineEdit::setMaxLength(int len)
{
	if (m_inputWidget)
	{
		m_inputWidget->SetMaxLength(len);
	}
}

bool QLineEdit::isReadOnly() const
{
	if (m_inputWidget)
	{
		return m_inputWidget->IsReadOnly();
	}
	return false;
}

void QLineEdit::setReadOnly(bool flag)
{
	if (m_inputWidget)
	{
		m_inputWidget->SetReadOnly(flag);
	}
}

int QLineEdit::maxLength() const
{
	if (m_inputWidget)
	{
		return m_inputWidget->MaxLength();
	}
	return 0;
}

void QLineEdit::selectAll()
{
    if(m_inputWidget)
    {
        m_inputWidget->SetFocus(ETrue);
    }

}

bool QLineEdit::edited() const
{
	if (m_inputWidget)
	{
		return m_inputWidget->Edited();
	}
	return false;
}

void QLineEdit::setEdited(bool flag)
{
	if (m_inputWidget)
	{
		return m_inputWidget->SetEdited(flag);
	}
}

QSize QLineEdit::sizeForCharacterWidth(int numCharacters) const
{
	if (m_inputWidget)
	{
		return QSize(m_inputWidget->SizeForCharacterWidth(numCharacters));
	}
	return QSize(0,0);
}


QRect QLineEdit::frameGeometry() const
{
	if(m_inputWidget)
	{
		return QRect(m_inputWidget->Rect());
	}
	return QRect();
}

void QLineEdit::setFrameGeometry(const QRect &r)
{
	if(m_inputWidget)
	{
		m_inputWidget->SetRect(r.Rect());
	}
}


int QLineEdit::baselinePosition(int height) const
{
    return height;
}

void QLineEdit::clicked()
{
    m_clicked.call();
}

void QLineEdit::setAlignment(AlignmentFlags alignment)
{

}

void QLineEdit::setWritingDirection(QPainter::TextDirection direction)
{
//TODO
}

QWidget::FocusPolicy QLineEdit::focusPolicy() const
{
    return TabFocus;
}

bool QLineEdit::checksDescendantsForFocus() const
{
    return true;
}


void QLineEdit::setLiveSearch(bool liveSearch)
{
}

void QLineEdit::setAutoSaveName(const QString& name)
{
}

void QLineEdit::setMaxResults(int maxResults)
{
}

void QLineEdit::setPlaceholderString(const QString& placeholder)
{
}

void QLineEdit::addSearchResult()
{
}

void QLineEdit::paint(QPainter *aPainter, const QRect& aRect)
{
	if (m_inputWidget)
	{
		TRect rect = aRect.Rect();
		m_inputWidget->Draw(aPainter->Gc(), rect);
	}
}
bool QLineEdit::isActive() const
{
	if (m_inputWidget)
	{
		return m_inputWidget->IsActive();
	}
	return false;
}

void QLineEdit::deActivate(bool acceptChanges)
{
	if (m_inputWidget)
	{
		m_inputWidget->DeActivate(acceptChanges);
	}
}
void QLineEdit::HandleEvent(TEvent aEvent)
{
	if(aEvent == EValueChanged)
	{
		textChanged();
	}
	else if (aEvent == EFocusOut && eventFilterObject())
	{
        QFocusEvent event(QEvent::FocusOut);
        const_cast<QObject *>(eventFilterObject())->eventFilter(this, &event);
	}
    else if(aEvent == EReturnPressed)
    {
        returnPressed();
    }
}

void QLineEdit::setSize(int size)
{
	if (m_inputWidget)
	{
		m_inputWidget->SetSize(size);
	}
}

⌨️ 快捷键说明

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