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

📄 qmrenameedit.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
字号:
/* qmrenameedit.cpp * * $Id: qmrenameedit.cpp,v 1.8.2.1 2002/09/23 19:26:51 kyllingstad Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmrenameedit.h"#include <qapplication.h>#include <qlistview.h>#include <qpainter.h>#include <iostream>/** * @file qmrenameedit.cpp * @brief Inline edit field widget *//*!  \class QmRenameEdit qmrenameedit.h  \brief Represents an inline edit field.  This widget is for use with inline renaming in listviews.  It  differs from QLineEdit visually, but more importantly, it  overrides some keys (such as Escape) and events to hide itself.*//*!  Constructs a rename edit field.*/QmRenameEdit::QmRenameEdit(	QWidget *parent)	: QLineEdit("", parent){	connect(this, SIGNAL(returnPressed()), this, SLOT(hide()));	setFrame(false);	selectAll();}/*!*/QmRenameEdit::~QmRenameEdit(){}/*!  Shows the widget and the default text.*/voidQmRenameEdit::show(){	setText(m_OriginalText);	selectAll();//	topLevelWidget()->child("control-bar")->installEventFilter(this);	QLineEdit::show();}/*!  Resizes and positions the widget so that it covers \a item.  The listview width is taken into account, as well as the  depth of the item when determining the width of the widget.  The widget will get the focus. */voidQmRenameEdit::position(	QListViewItem *item){	CHECK_PTR(item);	if(item == 0)		return;	m_OriginalText	= item->text(0);	QListView *lv	= item->listView();		connect(lv->horizontalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(rename()));	connect(lv->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int)));	connect(lv->verticalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(rename()));	connect(lv->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int)));	int depth		= item->depth() + 1;	int xpos  		= (depth * lv->treeStepSize()) + lv->itemMargin();	int ypos  		= item->itemPos() + 1;	int width 		= lv->width() - xpos - lv->itemMargin() * 2;	int height		= item->height() + lv->itemMargin() * 2 + 1; // *2 for margins, +1 for border	if(width > lv->columnWidth(0) - xpos + 50)		width = lv->columnWidth(0) - xpos + 50;		move(xpos, ypos);	resize(width, height);	setFocus();	show();//	topLevelWidget()->child("control-bar")->installEventFilter(this);//	topLevelWidget()->child("control-bar")->setFocusProxy(this);//	disconnect(lv->horizontalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(rename()));//	disconnect(lv->verticalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(rename()));}/*!  Override accelerator keys. */boolQmRenameEdit::eventFilter(	QObject *o,	QEvent *e){	if(e->type() == QEvent::KeyPress)	{		if(hasFocus())		{			keyPressEvent(dynamic_cast<QKeyEvent*>(e));			// Eat event			return true;		}	}		return QWidget::eventFilter(o, e);}/*!  Escape hides the widget.  Up and down are eaten, while the rest  is passed to QLineEdit, which again will pass the keys it doesn't  read to its parent. */voidQmRenameEdit::keyPressEvent(	QKeyEvent *e){	switch(e->key())	{	case Key_Escape://		topLevelWidget()->child("control-bar")->setFocusProxy(0);		hide();		emit newName(m_OriginalText);//		topLevelWidget()->child("control-bar")->removeEventFilter(this);		break;	case Key_Up:	case Key_Down:	case Key_PageUp:	case Key_PageDown:		// Eat keyevent		break;	case Key_Return:	case Key_Enter:		if(text().isEmpty())			qApp->beep();		else		{//			topLevelWidget()->child("control-bar")->setFocusProxy(0);			QLineEdit::keyPressEvent(e);			emit newName(text());//			topLevelWidget()->child("control-bar")->removeEventFilter(this);		}		break;	default:		QLineEdit::keyPressEvent(e);	}}/*!  This event occur when the widget looses keyboard focus.  When this happens,  the widget is hidden. */voidQmRenameEdit::focusOutEvent(	QFocusEvent *){	rename();}/*!  Paints a thin black border.*/voidQmRenameEdit::paintEvent(	QPaintEvent *e){	QLineEdit::paintEvent(e);	QPainter p(this);	p.setPen(black);	p.drawRect(rect());}/*!  Emits the appropriate new text. */voidQmRenameEdit::rename(){	if( ! text().isEmpty())		emit newName(text());	else		emit newName(m_OriginalText);	hide();//	topLevelWidget()->child("control-bar")->removeEventFilter(this);}/*! */voidQmRenameEdit::sliderMoved(int){	rename();}

⌨️ 快捷键说明

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