[prev in list] [next in list] [prev in thread] [next in thread]
List: kopete-devel
Subject: Re: [kopete-devel] [PATCH] Implement dynamic resizing of
From: Dmitry Suzdalev <dimsuzkde () gmail ! com>
Date: 2008-12-24 13:26:33
Message-ID: 200812241626.33570.dimsuz () gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Of course I forgot to attach it :-)
On Wednesday 24 of December 2008 16:25:35 Dmitry Suzdalev wrote:
> Hello guys! :)
>
> This patch will make kopetechatwindow's text edit part to grow or shrink
> dynamically as users enters/removes text into it.
> It starts being single line and then if user presses Enter or pastes some
> text or whatever, it will grow as needed. Likewise it will shrink if text
> is deleted.
>
> Growing happens up to some maximum size - currently it's set to 200 px (I
> feel that to be comfortable) and then vertiacl scrollbar will be added.
>
> I tested it for some time and with some different Qt styles, seems to work
> ok. Ah, one question. I guess this is what can be called a feature and 4.2
> is in feature freeze. So I can't commit it to trunk. What to do with this
> patch? :)
>
> Some notes:
> * Splitter is removed.
> * Currently I have hardcoded margins at top and bottom being 3px. I tried
> to find some way not to hardcode them, and get them from Qt, but didn't
> find a solution. We even had a conversation with some devs on #kde-devel
> about that and still no desirable solution was found. Initially text edit
> starts as single line, show it should look like QLineEdit. But even
> QLineEdit::sizeHint() has *hardcoded* margins in Qt sources.
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" \
content="1" /><style type="text/css">p, li { white-space: pre-wrap; \
}</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:10pt; \
font-weight:400; font-style:normal;">Of course I forgot to attach it :-)<br> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>On \
Wednesday 24 of December 2008 16:25:35 Dmitry Suzdalev wrote:<br> > Hello guys! \
:)<br> ><br>
> This patch will make kopetechatwindow's text edit part to grow or shrink<br>
> dynamically as users enters/removes text into it.<br>
> It starts being single line and then if user presses Enter or pastes some<br>
> text or whatever, it will grow as needed. Likewise it will shrink if text<br>
> is deleted.<br>
><br>
> Growing happens up to some maximum size - currently it's set to 200 px (I<br>
> feel that to be comfortable) and then vertiacl scrollbar will be added.<br>
><br>
> I tested it for some time and with some different Qt styles, seems to work<br>
> ok. Ah, one question. I guess this is what can be called a feature and 4.2<br>
> is in feature freeze. So I can't commit it to trunk. What to do with this<br>
> patch? :)<br>
><br>
> Some notes:<br>
> * Splitter is removed.<br>
> * Currently I have hardcoded margins at top and bottom being 3px. I tried<br>
> to find some way not to hardcode them, and get them from Qt, but didn't<br>
> find a solution. We even had a conversation with some devs on #kde-devel<br>
> about that and still no desirable solution was found. Initially text edit<br>
> starts as single line, show it should look like QLineEdit. But even<br>
> QLineEdit::sizeHint() has *hardcoded* margins in Qt sources.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"><br></p></body></html>
["editpart.diff" (text/x-patch)]
Index: chatview.h
===================================================================
--- chatview.h (revision 900539)
+++ chatview.h (working copy)
@@ -58,7 +58,7 @@
/**
* @author Olivier Goffart
*/
-class ChatView : public KVBox, public KopeteView
+class ChatView : public QWidget, public KopeteView
{
Q_OBJECT
public:
@@ -78,7 +78,7 @@
void addText( const QString &text );
/**
- * Saves window settings such as splitter positions
+ * Saves window settings
*/
void saveOptions();
@@ -382,7 +382,7 @@
void updateChatState( KopeteTabState state = Undefined );
/**
- * Read in saved options, such as splitter positions
+ * Read in saved options
*/
void readOptions();
Index: chattexteditpart.h
===================================================================
--- chattexteditpart.h (revision 900539)
+++ chattexteditpart.h (working copy)
@@ -176,6 +176,11 @@
private:
void setProtocolRichTextSupport();
+ /**
+ * Grow/shrink text editing area height as needed to display a message being typed
+ */
+ void updateHeight();
+
private:
Kopete::ChatSession *m_session;
Index: chatview.cpp
===================================================================
--- chatview.cpp (revision 900539)
+++ chatview.cpp (working copy)
@@ -67,19 +67,16 @@
bool isActive;
bool sendInProgress;
bool visibleMembers;
- QSplitter * splitter;
};
ChatView::ChatView( Kopete::ChatSession *mgr, ChatWindowPlugin *parent )
- : KVBox( 0l ), KopeteView( mgr, parent )
+ : KopeteView( mgr, parent )
, d(new KopeteChatViewPrivate)
{
d->isActive = false;
d->visibleMembers = false;
d->sendInProgress = false;
- KVBox *vbox=this;
-
m_mainWindow = 0L;
m_tabState = Normal;
@@ -87,20 +84,15 @@
//FIXME: don't widgets start off hidden anyway?
hide();
- d->splitter = new QSplitter( Qt::Vertical, vbox );
-
+ QVBoxLayout* layout = new QVBoxLayout(this);
//Create the view dock widget (KHTML Part), and set it to no docking (lock it in \
place) m_messagePart = new ChatMessagePart( mgr , this );
//Create the bottom dock widget, with the edit area, statusbar and send button
- m_editPart = new ChatTextEditPart( mgr, vbox );
+ m_editPart = new ChatTextEditPart( mgr, this );
- d->splitter->addWidget(m_messagePart->view());
- d->splitter->addWidget(m_editPart->widget());
- d->splitter->setChildrenCollapsible( false );
- QList<int> sizes;
- sizes << 240 << 40;
- d->splitter->setSizes( sizes );
+ layout->addWidget(m_messagePart->view());
+ layout->addWidget(m_editPart->widget());
// FIXME: is this used these days? it seems totally unnecessary
connect( editPart(), SIGNAL( toolbarToggled(bool)), this, \
SLOT(slotToggleRtfToolbar(bool)) ); @@ -297,10 +289,12 @@
makeVisible();
#ifdef Q_WS_X11
if ( !KWindowSystem::windowInfo( m_mainWindow->winId(), NET::WMDesktop \
).onAllDesktops() ) + {
if( Kopete::BehaviorSettings::self()->trayflashNotifySetCurrentDesktopToChatView() \
&& activate ) KWindowSystem::setCurrentDesktop( KWindowSystem::windowInfo( \
m_mainWindow->winId(), NET::WMDesktop ).desktop() ); else
KWindowSystem::setOnDesktop( m_mainWindow->winId(), \
KWindowSystem::currentDesktop() ); + }
#endif
if(m_mainWindow->isMinimized())
{
@@ -755,7 +749,6 @@
{
KSharedConfig::Ptr config = KGlobal::config();
KConfigGroup kopeteChatWindowMainWinSettings( config, ( msgManager()->form() == \
Kopete::ChatSession::Chatroom ? QLatin1String( "KopeteChatWindowGroupMode" ) : \
QLatin1String( "KopeteChatWindowIndividualMode" ) ) );
- kopeteChatWindowMainWinSettings.writeEntry( QLatin1String("ChatViewSplitter"), \
d->splitter->saveState().toBase64() ); saveChatSettings();
config->sync();
}
@@ -800,10 +793,6 @@
void ChatView::readOptions()
{
KConfigGroup kopeteChatWindowMainWinSettings( KGlobal::config(), ( \
msgManager()->form() == Kopete::ChatSession::Chatroom ? QLatin1String( \
"KopeteChatWindowGroupMode" ) : QLatin1String( "KopeteChatWindowIndividualMode" ) ) \
);
- //kDebug(14000) << "reading splitterpos from key: " << dockKey;
- QByteArray state;
- state = kopeteChatWindowMainWinSettings.readEntry( \
QLatin1String("ChatViewSplitter"), state );
- d->splitter->restoreState( QByteArray::fromBase64( state ) );
}
void ChatView::setActive( bool value )
Index: chattexteditpart.cpp
===================================================================
--- chattexteditpart.cpp (revision 900539)
+++ chattexteditpart.cpp (working copy)
@@ -43,12 +43,6 @@
mComplete->setIgnoreCase( true );
mComplete->setOrder( KCompletion::Weighted );
- // set params on the edit widget
- textEdit()->setMinimumSize( QSize( 75, 20 ) );
-// textEdit()->setWordWrap( Q3TextEdit::WidgetWidth );
-// textEdit()->setWrapPolicy( Q3TextEdit::AtWhiteSpace );
-// textEdit()->setAutoFormatting( Q3TextEdit::AutoNone );
-
// some signals and slots connections
connect( textEdit(), SIGNAL( textChanged()), this, SLOT( slotTextChanged() ) );
@@ -58,6 +52,9 @@
m_typingStopTimer = new QTimer(this);
m_typingStopTimer->setObjectName("m_typingStopTimer");
+ // init text edit height
+ updateHeight();
+
connect( m_typingRepeatTimer, SIGNAL( timeout() ), this, SLOT( \
slotRepeatTypingTimer() ) ); connect( m_typingStopTimer, SIGNAL( timeout() ), \
this, SLOT( slotStoppedTypingTimer() ) );
@@ -286,9 +283,27 @@
m_typingStopTimer->start( 4500 );
}
+ // shrink or grow textEdit() as needed
+ updateHeight();
+
emit canSendChanged( canSend() );
}
+void ChatTextEditPart::updateHeight()
+{
+ const int margin = 3;
+ const int maxHeight = 200;
+
+ QTextDocument* doc = textEdit()->document();
+ int height = margin + doc->size().height() + margin;
+
+ if ( height != textEdit()->size().height() )
+ {
+ kDebug() << "resizing";
+ textEdit()->setFixedHeight(qMin(height, maxHeight));
+ }
+}
+
void ChatTextEditPart::historyUp()
{
if ( historyList.empty() || historyPos == historyList.count() - 1 )
_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic