Commit 1f538de5 authored by Waldo Bastian's avatar Waldo Bastian
Browse files

* Reworked size handling (Thanks go to TrollTech for educating me)

* Added --noresize option to keep VT size fixed.
* Fixed connection of selection-begin slot.

svn path=/trunk/kdebase/konsole/; revision=231394
parent 4e2a4381
......@@ -325,6 +325,7 @@ TEWidget::TEWidget(QWidget *parent, const char *name)
,isPrinting(false)
,printerFriendly(false)
,printerBold(false)
,isFixedSize(false)
,m_drop(0)
,possibleTripleClick(false)
,mResizeWidget(0)
......@@ -557,7 +558,11 @@ void TEWidget::setCursorPos(const int curx, const int cury)
*/
void TEWidget::setImage(const ca* const newimg, int lines, int columns)
{ int y,x,len;
{
if (!image)
updateImageSize(); // Create image
int y,x,len;
const QPixmap* pm = backgroundPixmap();
QPainter paint;
setUpdatesEnabled(false);
......@@ -846,23 +851,26 @@ void TEWidget::blinkCursorEvent()
/* */
/* ------------------------------------------------------------------------- */
void TEWidget::resizeEvent(QResizeEvent* ev)
void TEWidget::resizeEvent(QResizeEvent*)
{
//printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
//printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
//printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
//printf("curren: %d,%d\n",width(),height());
HCNT("resizeEvent");
// see comment in `paintEvent' concerning the rounding.
//FIXME: could make a routine here; check width(),height()
assert(ev->size().width() == width());
assert(ev->size().height() == height());
propagateSize();
updateImageSize();
}
void TEWidget::propagateSize()
{
if (isFixedSize)
{
setSize(columns, lines);
QFrame::setFixedSize(sizeHint());
parentWidget()->adjustSize();
parentWidget()->setFixedSize(parentWidget()->sizeHint());
return;
}
if (image)
updateImageSize();
}
void TEWidget::updateImageSize()
{
ca* oldimg = image;
int oldlin = lines;
......@@ -918,6 +926,7 @@ void TEWidget::setScrollbarLocation(int loc)
if (scrollLoc == loc) return; // quickly
bY = bX = 1;
scrollLoc = loc;
calcGeometry();
propagateSize();
update();
}
......@@ -1761,17 +1770,21 @@ void TEWidget::calcGeometry()
scrollbar->show();
break;
}
columns = contentWidth / font_w;
if (columns<1) {
kdDebug(1211) << "TEWidget::calcGeometry: columns=" << columns << endl;
columns=1;
}
//FIXME: support 'rounding' styles
bY = rimY;
contentHeight = contentsRect().height() - 2 * rimY + /* mysterious */ 1;
lines = contentHeight / font_h;
if (!isFixedSize)
{
columns = contentWidth / font_w;
if (columns<1) {
kdDebug(1211) << "TEWidget::calcGeometry: columns=" << columns << endl;
columns=1;
}
lines = contentHeight / font_h;
}
}
void TEWidget::makeImage()
......@@ -1784,17 +1797,27 @@ void TEWidget::makeImage()
}
// calculate the needed size
QSize TEWidget::calcSize(int cols, int lins) const
void TEWidget::setSize(int cols, int lins)
{
int frw = width() - contentsRect().width();
int frh = height() - contentsRect().height();
int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh + /* mysterious */ 1 );
m_size = QSize(font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh + /* mysterious */ 1);
updateGeometry();
}
void TEWidget::setFixedSize(int cols, int lins)
{
isFixedSize = true;
columns = cols;
lines = lins;
setSize(cols, lins);
QFrame::setFixedSize(m_size);
}
QSize TEWidget::sizeHint() const
{
return size();
return m_size;
}
void TEWidget::styleChange(QStyle &)
......
......@@ -80,8 +80,9 @@ public:
void calcGeometry();
void propagateSize();
QSize calcSize(int cols, int lins) const;
void updateImageSize();
void setSize(int cols, int lins);
void setFixedSize(int cols, int lins);
QSize sizeHint() const;
void setWordCharacters(QString wc);
......@@ -247,6 +248,7 @@ private:
bool isPrinting; // Paint job is intended for printer
bool printerFriendly; // paint printer friendly, save ink
bool printerBold; // Use a bold font instead of overstrike for bold
bool isFixedSize; //Columns / lines are locked.
QTimer* blinkT; // active when hasBlinker
QTimer* blinkCursorT; // active when hasBlinkingCursor
......@@ -273,7 +275,8 @@ private:
// the rim should normally be 1, 0 only when running in full screen mode.
int rimX; // left/right rim width
int rimY; // top/bottom rim high
QSize m_size;
private slots:
void drop_menu_activated(int item);
void swapColorTable();
......
......@@ -147,8 +147,8 @@ void TEmulation::changeGUI(TEWidget* newgui)
this,SLOT(onHistoryCursorChange(int)));
QObject::disconnect(gui,SIGNAL(keyPressedSignal(QKeyEvent*)),
this,SLOT(onKeyPress(QKeyEvent*)));
QObject::disconnect(gui,SIGNAL(beginSelectionSignal(const int,const int)),
this,SLOT(onSelectionBegin(const int,const int)) );
QObject::disconnect(gui,SIGNAL(beginSelectionSignal(const int,const int,const bool)),
this,SLOT(onSelectionBegin(const int,const int,const bool)) );
QObject::disconnect(gui,SIGNAL(extendSelectionSignal(const int,const int)),
this,SLOT(onSelectionExtend(const int,const int)) );
QObject::disconnect(gui,SIGNAL(endSelectionSignal(const bool)),
......
......@@ -241,7 +241,8 @@ Konsole::Konsole(const char* name, const QString& _program, QStrList & _args, in
,m_menuCreated(false)
,skip_exit_query(false) // used to skip the query when closed by the session management
,b_warnQuit(false)
,b_allowResize(true)
,b_allowResize(true) // Whether application may resize
,b_fixedSize(false) // Whether user may resize
,b_addToUtmp(true)
,b_xonXoff(false)
,b_bidiEnabled(false)
......@@ -325,8 +326,6 @@ Konsole::Konsole(const char* name, const QString& _program, QStrList & _args, in
}
// activate and run first session //////////////////////////////////////////
// FIXME: this slows it down if --type is given, but prevents a crash (malte)
//KONSOLEDEBUG << "Konsole pgm: " << _program << endl;
newSession(co, _program, _args, _term, _icon, _title, _cwd);
//KONSOLEDEBUG<<"Konsole ctor() ends "<<time.elapsed()<<" msecs elapsed"<<endl;
......@@ -547,7 +546,8 @@ void Konsole::makeGUI()
// Fullscreen
m_options->insertSeparator();
m_fullscreen->plug(m_options);
if (m_fullscreen)
m_fullscreen->plug(m_options);
m_options->insertSeparator();
// Select Bell
......@@ -587,18 +587,21 @@ void Konsole::makeGUI()
m_options->insertItem( SmallIconSet( "colorize" ), i18n( "Sch&ema" ), m_schema);
// Select size
selectSize = new KonsoleFontSelectAction(i18n("S&ize"), 0, this,
if (!b_fixedSize)
{
selectSize = new KonsoleFontSelectAction(i18n("S&ize"), 0, this,
SLOT(slotSelectSize()), actions, "size");
QStringList sizeitems;
sizeitems << i18n("40x15 (&Small)")
<< i18n("80x24 (&VT100)")
<< i18n("80x25 (&IBM PC)")
<< i18n("80x40 (&XTerm)")
<< i18n("80x52 (IBM V&GA)")
<< ""
<< i18n("&Custom...");
selectSize->setItems(sizeitems);
selectSize->plug(m_options);
QStringList sizeitems;
sizeitems << i18n("40x15 (&Small)")
<< i18n("80x24 (&VT100)")
<< i18n("80x25 (&IBM PC)")
<< i18n("80x40 (&XTerm)")
<< i18n("80x52 (IBM V&GA)")
<< ""
<< i18n("&Custom...");
selectSize->setItems(sizeitems);
selectSize->plug(m_options);
}
KAction *historyType = new KAction(i18n("Hist&ory..."), "history", 0, this,
SLOT(slotHistoryType()), actions, "history");
......@@ -970,19 +973,29 @@ void Konsole::slotCouldNotClose()
void Konsole::setColLin(int columns, int lines)
{
if ((columns==0) || (lines==0))
if ((columns==0) || (lines==0))
{
if (defaultSize.isEmpty()) // not in config file : set default value
if (b_fixedSize || defaultSize.isEmpty())
{
defaultSize = sizeForCentralWidgetSize(te->calcSize(80,24));
notifySize(24,80); // set menu items (strange arg order !)
// not in config file : set default value
columns = 80;
lines = 24;
}
}
if ((columns==0) || (lines==0))
{
resize(defaultSize);
} else {
QSize size = te->calcSize(columns, lines);
resize(sizeForCentralWidgetSize(size));
if (!kapp->authorizeKAction("size"))
te->setFixedSize(size);
}
else
{
if (b_fixedSize)
te->setFixedSize(columns, lines);
else
te->setSize(columns, lines);
adjustSize();
if (b_fixedSize)
setFixedSize(sizeHint());
notifySize(lines,columns); // set menu items (strange arg order !)
}
}
......@@ -1448,6 +1461,11 @@ void Konsole::slotToggleMenubar() {
menubar->show();
else
menubar->hide();
if (b_fixedSize)
{
adjustSize();
setFixedSize(sizeHint());
}
if (!showMenubar->isChecked()) {
setCaption(i18n("Use the right mouse button to bring back the menu"));
QTimer::singleShot(5000,this,SLOT(updateTitle()));
......@@ -1462,11 +1480,17 @@ void Konsole::slotToggleToolbar() {
toolBar()->show();
else
toolBar()->hide();
if (b_fixedSize)
{
adjustSize();
setFixedSize(sizeHint());
}
}
void Konsole::slotToggleFullscreen()
{
setFullScreen(!b_fullscreen);
te->setFrameStyle( b_framevis && !b_fullscreen ?(QFrame::WinPanel|QFrame::Sunken):QFrame::NoFrame );
}
void Konsole::slotSaveSettings()
......@@ -1525,6 +1549,8 @@ void Konsole::changeColumns(int columns)
}
void Konsole::slotSelectSize() {
if (b_fullscreen)
slotToggleFullscreen();
int item = selectSize->currentItem();
switch (item) {
case 0: setColLin(40,15); break;
......@@ -1575,8 +1601,8 @@ void Konsole::initFullScreen()
//This function is to be called from main.C to initialize the state of the Konsole (fullscreen or not). It doesn't appear to work
//from inside the Konsole constructor
if (b_fullscreen) {
setColLin(0,0);
}
setColLin(0,0);
}
setFullScreen(b_fullscreen);
}
......@@ -1592,26 +1618,20 @@ void Konsole::initSessionKeyTab(const QString &keyTab) {
void Konsole::setFullScreen(bool on)
{
// if (on == b_fullscreen) {
// KONSOLEDEBUG << "On and b_Fullscreen both equal " << b_fullscreen << "." << endl;
// }
if (on) {
te->setRim(0);
showFullScreen();
b_fullscreen = on;
}
else {
te->setRim(1);
if( isFullScreen()) // showNormal() may also do unminimize, unmaximize etc.
showNormal();
updateTitle(); // restore caption of window
b_fullscreen = false;
// KONSOLEDEBUG << "On is false, b_fullscreen is " << b_fullscreen << ". Set to Normal view and set caption." << endl;
}
// return;
if (m_fullscreen!=0)
m_fullscreen->setChecked(b_fullscreen);
if (on) {
te->setFrameStyle( QFrame::NoFrame );
showFullScreen();
b_fullscreen = on;
}
else {
te->setFrameStyle( b_framevis?(QFrame::WinPanel|QFrame::Sunken):QFrame::NoFrame );
if( isFullScreen()) // showNormal() may also do unminimize, unmaximize etc.
showNormal();
updateTitle(); // restore caption of window
b_fullscreen = false;
}
if (m_fullscreen)
m_fullscreen->setChecked(b_fullscreen);
}
/* --| sessions |------------------------------------------------------------ */
......@@ -1748,7 +1768,7 @@ void Konsole::runSession(TESession* s)
void Konsole::addSession(TESession* s)
{
QString newTitle = s->Title();
QString newTitle = s->Title();
bool nameOk;
int count = 1;
......@@ -2680,7 +2700,7 @@ void Konsole::detachSession() {
b_framevis?(QFrame::WinPanel|QFrame::Sunken):QFrame::NoFrame,
schema,te->font(),te->isBellMode(),te->wordCharacters(),
te->blinkingCursor(),te->ctrlDrag(),te->isTerminalSizeHint(),
te->lineSpacing(),te->cutToBeginningOfLine(),b_allowResize);
te->lineSpacing(),te->cutToBeginningOfLine(),b_allowResize, b_fixedSize);
detached.append(konsolechild);
konsolechild->show();
konsolechild->run();
......@@ -3329,4 +3349,14 @@ void Konsole::enableFullScripting(bool b)
se->enableFullScripting(b);
}
void Konsole::enableFixedSize(bool b)
{
b_fixedSize = b;
if (b_fixedSize)
{
delete m_fullscreen;
m_fullscreen = 0;
}
}
#include "konsole.moc"
......@@ -82,6 +82,7 @@ public:
void setSchema(const QString & path);
void enableFullScripting(bool b);
void enableFixedSize(bool b);
void run();
void setDefaultSession(const QString &filename);
......@@ -352,7 +353,8 @@ private:
bool skip_exit_query:1;
bool b_warnQuit:1;
bool isRestored:1;
bool b_allowResize:1;
bool b_allowResize:1; // Whether application may resize
bool b_fixedSize:1; // Whether user may resize
bool b_addToUtmp:1;
bool b_xonXoff:1;
bool b_bidiEnabled:1;
......
......@@ -23,12 +23,13 @@
KonsoleChild::KonsoleChild(TESession* _se, int columns, int lines, int scrollbar_location, int frame_style,
ColorSchema* _schema,QFont font,int bellmode,QString wordcharacters,
bool blinkingCursor, bool ctrlDrag, bool terminalSizeHint, int lineSpacing,
bool cutToBeginningOfLine, bool _allowResize):KMainWindow()
bool cutToBeginningOfLine, bool _allowResize, bool _fixedSize):KMainWindow()
,session_terminated(false)
,wallpaperSource(0)
,se(_se)
,schema(_schema)
,allowResize(_allowResize)
,b_fixedSize(_fixedSize)
{
te = new TEWidget(this);
te->setVTFont(font);
......@@ -165,9 +166,18 @@ void KonsoleChild::restoreAllListenToKeyPress()
void KonsoleChild::setColLin(int columns, int lines)
{
if ((columns==0) || (lines==0))
resize(sizeForCentralWidgetSize(te->calcSize(80,24)));
{
columns = 80;
lines = 24;
}
if (b_fixedSize)
te->setFixedSize(columns, lines);
else
resize(sizeForCentralWidgetSize(te->calcSize(columns, lines)));
te->setSize(columns, lines);
adjustSize();
if (b_fixedSize)
setFixedSize(sizeHint());
if (schema && schema->alignment() >= 3)
pixmap_menu_activated(schema->alignment(),schema->imagePath());
}
......
......@@ -34,7 +34,7 @@ public:
KonsoleChild(TESession*, int columns, int lines, int scrollbar_location, int frame_style,
ColorSchema* schema,QFont font, int bellmode, QString wordcharacters,
bool blinkingCursor, bool ctrlDrag, bool terminalSizeHint, int lineSpacing,
bool cutToBeginningOfLine, bool allowResize);
bool cutToBeginningOfLine, bool allowResize, bool fixedSize);
void run();
void setSchema(ColorSchema* s);
~KonsoleChild();
......@@ -59,7 +59,7 @@ private slots:
void attachSession();
void renameSession();
void closeSession();
private:
void setColLin(int columns, int lines);
void pixmap_menu_activated(int item,QString pmPath);
......@@ -71,6 +71,7 @@ private:
TESession* se;
ColorSchema* schema;
bool allowResize;
bool b_fixedSize;
TEWidget* te;
KPopupMenu* m_rightButton;
KRootPixmap* rootxpm;
......
......@@ -24,14 +24,14 @@ KonsoleBookmarkHandler::KonsoleBookmarkHandler( Konsole *konsole, bool toplevel
{
m_menu = new KPopupMenu( konsole, "bookmark menu" );
QString file = locate( "data", "kfile/bookmarks.xml" );
if ( file.isEmpty() )
file = locateLocal( "data", "kfile/bookmarks.xml" );
m_file = locate( "data", "kfile/bookmarks.xml" );
if ( m_file.isEmpty() )
m_file = locateLocal( "data", "kfile/bookmarks.xml" );
KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false);
KBookmarkManager *manager = KBookmarkManager::managerForFile( m_file, false);
// import old bookmarks
if ( !KStandardDirs::exists( file ) ) {
if ( !KStandardDirs::exists( m_file ) ) {
QString oldFile = locate( "data", "kfile/bookmarks.html" );
if ( !oldFile.isEmpty() )
importOldBookmarks( oldFile, manager );
......@@ -53,6 +53,16 @@ KonsoleBookmarkHandler::KonsoleBookmarkHandler( Konsole *konsole, bool toplevel
}
}
void KonsoleBookmarkHandler::slotEditBookmarks()
{
KProcess proc;
proc << QString::fromLatin1("keditbookmarks");
proc << "--nobrowser";
proc << "--caption" << i18n("Konsole Bookmarks Editor");
proc << m_file;
proc.start(KProcess::DontCare);
}
QString KonsoleBookmarkHandler::currentURL() const
{
return m_konsole->baseURL().prettyURL();
......
......@@ -30,6 +30,7 @@ public:
private slots:
void slotBookmarksChanged( const QString &, const QString & caller );
void slotEditBookmarks();
signals:
void openURL( const QString& url, const QString& title );
......@@ -40,6 +41,7 @@ private:
Konsole *m_konsole;
KPopupMenu *m_menu;
KonsoleBookmarkMenu *m_bookmarkMenu;
QString m_file;
protected:
virtual void virtual_hook( int id, void* data );
......
......@@ -50,6 +50,7 @@ static KCmdLineOptions options[] =
{ "noscrollbar", I18N_NOOP("Do not display scrollbar"), 0 },
{ "noxft", I18N_NOOP("Do not use XFT (Anti-Aliasing)"), 0 },
{ "vt_sz CCxLL", I18N_NOOP("Terminal size in columns x lines"), 0 },
{ "noresize", I18N_NOOP("Terminal size is fixed"), 0 },
{ "type <type>", I18N_NOOP("Open the given session type instead of the default shell"), 0 },
{ "keytab <name>", I18N_NOOP("Use given .keytab file"), 0 },
{ "profile <name>", I18N_NOOP("Start with given sessions profile"), 0 },
......@@ -66,6 +67,7 @@ static bool has_noxft = false;
static bool login_shell = false;
static bool full_script = false;
static bool auto_close = true;
static bool fixed_size = false;
const char *konsole_shell(QStrList &args)
{
......@@ -116,6 +118,8 @@ public:
restartCommand.append("--script");
if (!auto_close)
restartCommand.append("--noclose");
if (fixed_size)
restartCommand.append("--noresize");
sm.setRestartCommand(restartCommand);
return true;
}
......@@ -253,6 +257,7 @@ int main(int argc, char* argv[])
wname = qtargs->getOption("name");
full_script = args->isSet("script");
auto_close = args->isSet("close");
fixed_size = !args->isSet("resize");
if (!full_script)
a.dcopClient()->setQtBridgeEnabled(false);
......@@ -305,6 +310,9 @@ int main(int argc, char* argv[])
}
}
if (!kapp->authorizeKAction("size"))
fixed_size = true;
// ///////////////////////////////////////////////
// Ignore SIGHUP so that we don't get killed when
......@@ -346,6 +354,7 @@ int main(int argc, char* argv[])
sCwd = sessionconfig->readEntry("Cwd0");
Konsole *m = new Konsole(wname,sPgm,eargs,histon,menubaron,toolbaron,frameon,scrollbaron,sIcon,sTitle,0/*type*/,sTerm,true,sCwd);
m->enableFullScripting(full_script);
m->enableFixedSize(fixed_size);
m->restore(n);
m->makeGUI();
m->setSchema(sessionconfig->readEntry("Schema0"));
......@@ -409,6 +418,7 @@ int main(int argc, char* argv[])
{
Konsole* m = new Konsole(wname,(shell ? QFile::decodeName(shell) : QString::null),eargs,histon,menubaron,toolbaron,frameon,scrollbaron,QString::null,title,type,term);
m->enableFullScripting(full_script);
m->enableFixedSize(fixed_size);
//3.8 :-(
//exit(0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment