Example #1
0
TailView::TailView(QWidget * parent):
    QAbstractScrollArea(parent),
    m_document(new YTextDocument),
    m_isActive(false),
    m_leftMouseIsDown(false),
    m_hasUnviewedChanges(false),
    m_layoutType(AutomaticLayout),
    m_layoutStrategy(new PartialLayout(this)),
    m_exactScrollBarController(new ExactScrollBarController(this)),
    m_approximateScrollBarController(new ApproximateScrollBarController(this)),
    m_scrollBarStrategy(m_approximateScrollBarController.data()),
    m_followTail(true),
    m_documentSearch(new DocumentSearch(m_document.data()))
{
    connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), SLOT(vScrollBarAction(int)));
    connect(Preferences::instance(), SIGNAL(preferencesChanged()), SLOT(onPreferencesChanged()));

    QAction * copy = new QAction(tr("&Copy"), this);
    copy->setShortcut(QKeySequence(QKeySequence::Copy));
    connect(copy, SIGNAL(triggered()), SLOT(onCopy()));
    addAction(copy);

    QAction * separator = new QAction(this);
    separator->setSeparator(true);
    addAction(separator);

    QAction * selectAll = new QAction(tr("Select &All"), this);
    selectAll->setShortcut(QKeySequence(QKeySequence::SelectAll));
    connect(selectAll, SIGNAL(triggered()), SLOT(onSelectAll()));
    addAction(selectAll);
    setContextMenuPolicy(Qt::ActionsContextMenu);
}
Example #2
0
void TailView::mouseReleaseEvent(QMouseEvent * event)
{
    if(event->button() == Qt::LeftButton) {
        m_leftMouseIsDown = false;
        mouseMoveEvent(event);
        onCopy(true);
    }
}
Example #3
0
void MediaView::keyPressEvent(QKeyEvent *e) {
	if (!_menu && e->key() == Qt::Key_Escape) {
		onClose();
	} else if (e == QKeySequence::Save || e == QKeySequence::SaveAs) {
		onSave();
	} else if (e->key() == Qt::Key_Copy || (e->key() == Qt::Key_C && e->modifiers().testFlag(Qt::ControlModifier))) {
		onCopy();
	} else if (e->key() == Qt::Key_Left) {
		moveToPhoto(-1);
	} else if (e->key() == Qt::Key_Right) {
		moveToPhoto(1);
	}
}
Example #4
0
void MediaView::contextMenuEvent(QContextMenuEvent *e) {
	if (_photo && _photo->full->loaded() && (e->reason() != QContextMenuEvent::Mouse || QRect(_x, _y, _current.width() / cIntRetinaFactor(), _current.height() / cIntRetinaFactor()).contains(e->pos()))) {
		
		if (_menu) {
			_menu->deleteLater();
			_menu = 0;
		}
		_menu = new QMenu(this);
		_menu->addAction(lang(lng_context_save_image), this, SLOT(onSave()))->setEnabled(true);
		_menu->addAction(lang(lng_context_copy_image), this, SLOT(onCopy()))->setEnabled(true);
		_menu->addAction(lang(lng_context_close_image), this, SLOT(onClose()))->setEnabled(true);
		if (_msgid) {
			_menu->addAction(lang(lng_context_forward_image), this, SLOT(onForward()))->setEnabled(true);
			_menu->addAction(lang(lng_context_delete_image), this, SLOT(onDelete()))->setEnabled(true);
		} else if ((App::self() && App::self()->photoId == _photo->id) || (_photo->chat && _photo->chat->photoId == _photo->id)) {
			_menu->addAction(lang(lng_context_delete_image), this, SLOT(onDelete()))->setEnabled(true);
		}
		_menu->setAttribute(Qt::WA_DeleteOnClose);
		connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroy(QObject*)));
		_menu->popup(e->globalPos());
		e->accept();
	}
}
void DesignerEventHandler::onContextMenu(QContextMenuEvent * e)
{
  QMenu * menu = new QMenu(parentWidget);

  QAction * copy_action     = menu->addAction(tr("Copy"), this, SLOT(onCopy()));
  menu->addAction(tr("Paste"), this, SLOT(onPaste()));
  QAction * delete_action   = menu->addAction(tr("Delete"), this, SLOT(onDelete()));
  QAction * delete_with_s_action   = menu->addAction(tr("Delete with sourcers"), this, SLOT(onDeleteWithSourcers()));
  QMenu* go = menu->addMenu(tr("Geometry operations"));
  go->addAction(tr("Align left") , this, SLOT(onAlignLeft()));
  go->addAction(tr("Align top")  , this, SLOT(onAlignTop()));
  go->addAction(tr("Align right"), this, SLOT(onAlignRight()));
  go->addAction(tr("Align bottom"),this, SLOT(onAlignBottom()));
  go->addAction(tr("Align vertical"),this, SLOT(onAlignVertical()));
  go->addAction(tr("Align horisontal"), this, SLOT (onAlignHorizontal()) );
  go->addAction(tr("Queue x"), this, SLOT (onQuequeX()) );
  go->addAction(tr("Queue y"), this, SLOT (onQuequeY()) );
  go->insertSeparator();
  go->addAction(tr("Same width"), this, SLOT(onSameWidth()));
  go->addAction(tr("Same height"), this, SLOT(onSameHeight()));
  QMenu* popupWindows = menu->addMenu(tr("Popup windows"));
  QMenu* leftButtonPW = popupWindows->addMenu(tr("Left button"));
  QAction * left_pw_add_action    = leftButtonPW->addAction( tr("Add"), this, SLOT(onLeftPwAdd()));
  QAction * left_pw_copy_action   = leftButtonPW->addAction( tr("Copy"), this, SLOT(onLeftPwCopy()));
  leftButtonPW->addAction( tr("Paste"), this, SLOT(onLeftPwPaste()));
  QAction * left_pw_delete_action = leftButtonPW->addAction( tr("Delete"), this, SLOT(onLeftDelete()));
  QMenu* rightButtonPW = popupWindows->addMenu (tr ("Right button"));
  QAction * right_pw_add_action    = rightButtonPW->addAction( tr("Add"), this, SLOT(onRightPwAdd()));
  QAction * right_pw_copy_action   = rightButtonPW->addAction( tr("Copy"), this, SLOT(onRightPwCopy()));
  rightButtonPW->addAction( tr("Paste"), this, SLOT(onRightPwPaste()));
  QAction * right_pw_delete_action = rightButtonPW->addAction( tr("Delete"), this, SLOT(onRightDelete()));

  QAction* show_properties_action = menu->addAction(tr("Properties"), this, SLOT(showProps()));
  QFont f = show_properties_action->font();
  f.setBold(true);
  show_properties_action->setFont(f);

  menu->addAction( tr("Export lists"), this, SLOT(onExportLists()) );
  //menu->insertSeparator();
  QMenu * predef = menu->addMenu ("Predef windows");
  QStringList names = PredefPw::Factory::availableNames();
  for (QStringList::iterator iter = names.begin(); iter != names.end(); ++iter ) {
    QAction * a = predef->addAction (*iter);
    //a->setMenu (predef);
    a->setData (12345);
  }
  
  menu->addAction ( "Find sourcer", this, SLOT (onFindSourcerByWidget() ) );
   
  if (selected_widgets.count( ) == 0 ){
    copy_action->setEnabled(false);
    delete_action->setEnabled(false);
    delete_with_s_action->setEnabled(false);
    go->setEnabled(false);
    popupWindows->setEnabled(false);
  }
  else {
    VtlWidget * w = (VtlWidget*)checkWidget(e->pos());
    if (w) {
      if (w->isLbPopupCreated()) {
        left_pw_add_action->setEnabled(false);
      }
      else {
        left_pw_copy_action->setEnabled(false);
        left_pw_delete_action->setEnabled(false);
      }
      if (w->isRbPopupCreated()) {
        right_pw_add_action->setEnabled(false);
      }
      else {
        right_pw_copy_action->setEnabled(false);
        right_pw_delete_action->setEnabled(false);
      }
    }
  }
  
  if ( context_widget )
    context_widget->prepareContextMenu (menu);
  
  if (e->state() & Qt::ControlModifier )
    control_modifier = true;
    
  QAction * a = menu->exec(e->globalPos());
  
  control_modifier = false;
  
  if ( a && a->data().toInt() == 12345 ) {
    QMessageBox box ( vtl::app );
    QAbstractButton * left_btn  = box.addButton ("Left" , QMessageBox::ActionRole );
    QAbstractButton * right_btn = box.addButton ("Right", QMessageBox::ActionRole );
    box.setWindowTitle ("Mouse button?");
    
    box.exec ();
    if ( box.clickedButton()     == left_btn ) {
      for (SWPtrList::iterator iter = selected_widgets.begin(); iter != selected_widgets.end(); ++iter )  {
         (*iter)->createLbPredefPw ( a->text() );
      }
    }
    else if (box.clickedButton() == right_btn ) {
      for (SWPtrList::iterator iter = selected_widgets.begin(); iter != selected_widgets.end(); ++iter )  {
         (*iter)->createRbPredefPw ( a->text() );
      }
    }
  }

  delete menu;
}
bool GuiTextEditCtrl::onKeyDown(const GuiEvent &event)
{
   if ( !isActive() || !isAwake() )
      return false;

   S32 stringLen = mTextBuffer.length();
   setUpdate();

   // Ugly, but now I'm cool like MarkF.
   if(event.keyCode == KEY_BACKSPACE)
      goto dealWithBackspace;
   
   if ( event.modifier & SI_SHIFT )
   {

      // Added support for word jump selection.

      if ( event.modifier & SI_CTRL )
      {
         switch ( event.keyCode )
         {
            case KEY_LEFT:
            {
               S32 newpos = findPrevWord();               

               if ( mBlockStart == mBlockEnd )
               {
                  // There was not already a selection so start a new one.
                  mBlockStart = newpos;
                  mBlockEnd = mCursorPos;
               }
               else
               {
                  // There was a selection already...
                  // In this case the cursor MUST be at either the
                  // start or end of that selection.

                  if ( mCursorPos == mBlockStart )
                  {
                     // We are at the start block and traveling left so
                     // just extend the start block farther left.                     
                     mBlockStart = newpos;
                  }
                  else
                  {
                     // We are at the end block BUT traveling left
                     // back towards the start block...

                     if ( newpos > mBlockStart )
                     {
                        // We haven't overpassed the existing start block
                        // so just trim back the end block.
                        mBlockEnd = newpos;
                     }
                     else if ( newpos == mBlockStart )
                     {
                        // We are back at the start, so no more selection.
                        mBlockEnd = mBlockStart = 0;
                     }
                     else
                     {
                        // Only other option, we just backtracked PAST
                        // our original start block.
                        // So the new position becomes the start block
                        // and the old start block becomes the end block.
                        mBlockEnd = mBlockStart;
                        mBlockStart = newpos;
                     }
                  }
               }
                              
               mCursorPos = newpos;

               return true;
            }

            case KEY_RIGHT:
            {
               S32 newpos = findNextWord();               

               if ( mBlockStart == mBlockEnd )
               {
                  // There was not already a selection so start a new one.
                  mBlockStart = mCursorPos;
                  mBlockEnd = newpos;
               }
               else
               {
                  // There was a selection already...
                  // In this case the cursor MUST be at either the
                  // start or end of that selection.

                  if ( mCursorPos == mBlockEnd )
                  {
                     // We are at the end block and traveling right so
                     // just extend the end block farther right.                     
                     mBlockEnd = newpos;
                  }
                  else
                  {
                     // We are at the start block BUT traveling right
                     // back towards the end block...

                     if ( newpos < mBlockEnd )
                     {
                        // We haven't overpassed the existing end block
                        // so just trim back the start block.
                        mBlockStart = newpos;
                     }
                     else if ( newpos == mBlockEnd )
                     {
                        // We are back at the end, so no more selection.
                        mBlockEnd = mBlockStart = 0;
                     }
                     else
                     {
                        // Only other option, we just backtracked PAST
                        // our original end block.
                        // So the new position becomes the end block
                        // and the old end block becomes the start block.
                        mBlockStart = mBlockEnd;
                        mBlockEnd = newpos;
                     }
                  }
               }

               mCursorPos = newpos;

               return true;
            }
            
            default:
               break;
         }
      }

      // End support for word jump selection.


        switch ( event.keyCode )
        {
            case KEY_TAB:
               if ( mTabComplete )
               {
				  onTabComplete_callback("1");
                  return true;
               }
			   break; // We don't want to fall through if we don't handle the TAB here.

            case KEY_HOME:
               mBlockStart = 0;
               mBlockEnd = mCursorPos;
               mCursorPos = 0;
               return true;

            case KEY_END:
                mBlockStart = mCursorPos;
                mBlockEnd = stringLen;
                mCursorPos = stringLen;
                return true;

            case KEY_LEFT:
                if ((mCursorPos > 0) & (stringLen > 0))
                {
                    //if we already have a selected block
                    if (mCursorPos == mBlockEnd)
                    {
                        mCursorPos--;
                        mBlockEnd--;
                        if (mBlockEnd == mBlockStart)
                        {
                            mBlockStart = 0;
                            mBlockEnd = 0;
                        }
                    }
                    else {
                        mCursorPos--;
                        mBlockStart = mCursorPos;

                        if (mBlockEnd == 0)
                        {
                            mBlockEnd = mCursorPos + 1;
                        }
                    }
                }
                return true;

            case KEY_RIGHT:
                if (mCursorPos < stringLen)
                {
                    if ((mCursorPos == mBlockStart) && (mBlockEnd > 0))
                    {
                        mCursorPos++;
                        mBlockStart++;
                        if (mBlockStart == mBlockEnd)
                        {
                            mBlockStart = 0;
                            mBlockEnd = 0;
                        }
                    }
                    else
                    {
                        if (mBlockEnd == 0)
                        {
                            mBlockStart = mCursorPos;
                            mBlockEnd = mCursorPos;
                        }
                        mCursorPos++;
                        mBlockEnd++;
                    }
                }
                return true;

				case KEY_RETURN:
				case KEY_NUMPADENTER:
           
					return dealWithEnter(false);

            default:
               break;
        }
    }
   else if (event.modifier & SI_CTRL)
   {
      switch(event.keyCode)
      {
#if defined(TORQUE_OS_MAC)
         // Added UNIX emacs key bindings - just a little hack here...

         // Ctrl-B - move one character back
         case KEY_B:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_LEFT;
            return(onKeyDown(new_event));
         }

         // Ctrl-F - move one character forward
         case KEY_F:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_RIGHT;
            return(onKeyDown(new_event));
         }

         // Ctrl-A - move to the beginning of the line
         case KEY_A:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_HOME;
            return(onKeyDown(new_event));
         }

         // Ctrl-E - move to the end of the line
         case KEY_E:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_END;
            return(onKeyDown(new_event));
         }

         // Ctrl-P - move backward in history
         case KEY_P:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_UP;
            return(onKeyDown(new_event));
         }

         // Ctrl-N - move forward in history
         case KEY_N:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_DOWN;
            return(onKeyDown(new_event));
         }

         // Ctrl-D - delete under cursor
         case KEY_D:
         { 
            GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_DELETE;
            return(onKeyDown(new_event));
         }

         case KEY_U:
         { 
            GuiEvent new_event;
            new_event.modifier = SI_CTRL;
            new_event.keyCode = KEY_DELETE;
            return(onKeyDown(new_event));
         }

         // End added UNIX emacs key bindings
#endif

         // Adding word jump navigation.

         case KEY_LEFT:
         {

            mCursorPos = findPrevWord();
            mBlockStart = 0;
            mBlockEnd = 0;
            return true;
         }

         case KEY_RIGHT:
         {
            mCursorPos = findNextWord();
            mBlockStart = 0;
            mBlockEnd = 0;
            return true;
         }         
         
#if !defined(TORQUE_OS_MAC)
         // Select all
         case KEY_A:
         {
            selectAllText();
            return true;
         }

         // windows style cut / copy / paste / undo keybinds
         case KEY_C:
         case KEY_X:
         {
            // copy, and cut the text if we hit ctrl-x
            onCopy( event.keyCode==KEY_X );
            return true;
         }
         case KEY_V:
         {
            onPaste();

            // Execute the console command!
            execConsoleCallback();
            return true;
         }

         case KEY_Z:
            if (! mDragHit)
            {
               onUndo();
               return true;
            }
#endif

         case KEY_DELETE:
         case KEY_BACKSPACE:
            //save the current state
            saveUndoState();

            //delete everything in the field
            mTextBuffer.set("");
            mCursorPos  = 0;
            mBlockStart = 0;
            mBlockEnd   = 0;

            execConsoleCallback();
            onChangeCursorPos(); //.logicking
            return true;
         default:
            break;
      }
   }
#if defined(TORQUE_OS_MAC)
   // mac style cut / copy / paste / undo keybinds
   else if (event.modifier & SI_ALT)
   {
      // Mac command key maps to alt in torque.

      // Added Mac cut/copy/paste/undo keys
      switch(event.keyCode)
      {
         // Select all
         case KEY_A:
         {
            selectAllText();
            return true;
         }
         case KEY_C:
         case KEY_X:
         {
            // copy, and cut the text if we hit cmd-x
            onCopy( event.keyCode==KEY_X );
            return true;
         }
         case KEY_V:
         {
            onPaste();

            // Execute the console command!
            execConsoleCallback();

            return true;
         }
            
         case KEY_Z:
            if (! mDragHit)
            {
               onUndo();
               return true;
            }
            
         default:
            break;
      }
   }
#endif
   else
   {
      switch(event.keyCode)
      {
         case KEY_ESCAPE:
            if( mEscapeCommand.isNotEmpty() )
            {
               evaluate( mEscapeCommand );
               return( true );
            }
            return( Parent::onKeyDown( event ) );

         case KEY_RETURN:
         case KEY_NUMPADENTER:
           
				return dealWithEnter(true);

         case KEY_UP:
         {
            if( mHistorySize > 0 )
            {
               if(mHistoryDirty)
               {
                  updateHistory(&mTextBuffer, false);
                  mHistoryDirty = false;
               }

               mHistoryIndex--;
               
               if(mHistoryIndex >= 0 && mHistoryIndex <= mHistoryLast)
                  setText(mHistoryBuf[mHistoryIndex]);
               else if(mHistoryIndex < 0)
                  mHistoryIndex = 0;
            }
               
            return true;
         }

         case KEY_DOWN:
         {
            if( mHistorySize > 0 )
            {
               if(mHistoryDirty)
               {
                  updateHistory(&mTextBuffer, false);
                  mHistoryDirty = false;
               }
               mHistoryIndex++;
               if(mHistoryIndex > mHistoryLast)
               {
                  mHistoryIndex = mHistoryLast + 1;
                  setText("");
               }
               else
                  setText(mHistoryBuf[mHistoryIndex]);
            }
            return true;
         }

         case KEY_LEFT:
            
            // If we have a selection put the cursor to the left side of it.
            if ( mBlockStart != mBlockEnd )
            {
               mCursorPos = mBlockStart;
               mBlockStart = mBlockEnd = 0;
            }
            else
            {
               mBlockStart = mBlockEnd = 0;
               mCursorPos = getMax( mCursorPos - 1, 0 );               
            }

            return true;

         case KEY_RIGHT:

            // If we have a selection put the cursor to the right side of it.            
            if ( mBlockStart != mBlockEnd )
            {
               mCursorPos = mBlockEnd;
               mBlockStart = mBlockEnd = 0;
            }
            else
            {
               mBlockStart = mBlockEnd = 0;
               mCursorPos = getMin( mCursorPos + 1, stringLen );               
            }

            return true;

         case KEY_BACKSPACE:
dealWithBackspace:
            //save the current state
            saveUndoState();

            if (mBlockEnd > 0)
            {
               mTextBuffer.cut(mBlockStart, mBlockEnd-mBlockStart);
               mCursorPos  = mBlockStart;
               mBlockStart = 0;
               mBlockEnd   = 0;
               mHistoryDirty = true;

               // Execute the console command!
               execConsoleCallback();

            }
            else if (mCursorPos > 0)
            {
               mTextBuffer.cut(mCursorPos-1, 1);
               mCursorPos--;
               mHistoryDirty = true;

               // Execute the console command!
               execConsoleCallback();
            }
            return true;

         case KEY_DELETE:
            //save the current state
            saveUndoState();

            if (mBlockEnd > 0)
            {
               mHistoryDirty = true;
               mTextBuffer.cut(mBlockStart, mBlockEnd-mBlockStart);

               mCursorPos = mBlockStart;
               mBlockStart = 0;
               mBlockEnd = 0;

               // Execute the console command!
               execConsoleCallback();
            }
            else if (mCursorPos < stringLen)
            {
               mHistoryDirty = true;
               mTextBuffer.cut(mCursorPos, 1);

               // Execute the console command!
               execConsoleCallback();
            }
            return true;

         case KEY_INSERT:
            mInsertOn = !mInsertOn;
            return true;

         case KEY_HOME:
            mBlockStart = 0;
            mBlockEnd   = 0;
            mCursorPos  = 0;
            return true;

         case KEY_END:
            mBlockStart = 0;
            mBlockEnd   = 0;
            mCursorPos  = stringLen;
            return true;
      
         default:
            break;

         }
   }

   switch ( event.keyCode )
   {
      case KEY_TAB:
         if ( mTabComplete )
         {
			onTabComplete_callback("0");
            return( true );
         }
      case KEY_UP:
      case KEY_DOWN:
      case KEY_ESCAPE:
         return Parent::onKeyDown( event );
      default:
         break;
   }
         
   // Handle character input events.

   if( mProfile->mFont->isValidChar( event.ascii ) )
   {
      handleCharInput( event.ascii );
      return true;
   }

   // Or eat it if that's appropriate.
   if( mSinkAllKeyEvents )
      return true;

   // Not handled - pass the event to it's parent.
   return Parent::onKeyDown( event );
}