Development/Tutorials/Using KXmlGuiWindow (pt BR): Difference between revisions

    From KDE TechBase
    No edit summary
    No edit summary
     
    (7 intermediate revisions by 2 users not shown)
    Line 1: Line 1:
    {{Template:I18n/Language Navigation Bar|Development/Tutorials/Using_KXmlGuiWindow}}
     
    {{TutorialBrowser_(pt_BR)|
    {{TutorialBrowser_(pt_BR)|


    Line 8: Line 8:
    pre=[[Development/Tutorials/First_program_(pt_BR)|Tutorial 1 - Alô Mundo]]|
    pre=[[Development/Tutorials/First_program_(pt_BR)|Tutorial 1 - Alô Mundo]]|


    next=[[Development/Tutorials/Using_KActions_(pt_BR)|Tutorial 3 - KActions e XMLGUI]]|  
    next=[[Development/Tutorials/Using_KActions|Tutorial 3 - KActions e XMLGUI]]|  


    reading={{class|KXmlGuiWindow}}
    reading={{class|KXmlGuiWindow}}
    Line 27: Line 27:


    ===mainwindow.h===
    ===mainwindow.h===
    <code cppqt n>
    <syntaxhighlight lang="cpp-qt" line>
    #ifndef MAINWINDOW_H
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #define MAINWINDOW_H
    Line 44: Line 44:


    #endif
    #endif
    </code>
    </syntaxhighlight>
    First we Subclass KXmlGuiWindow on line 7 with <tt>class MainWindow : public KXmlGuiWindow</tt>.
    First we Subclass KXmlGuiWindow on line 7 with <tt>class MainWindow : public KXmlGuiWindow</tt>.


    Line 52: Line 52:


    ===mainwindow.cpp===
    ===mainwindow.cpp===
    <code cppqt n>
    <syntaxhighlight lang="cpp-qt" line>
    #include "mainwindow.h"
    #include "mainwindow.h"


    Line 61: Line 61:
       setupGUI();
       setupGUI();
    }
    }
    </code>
    </syntaxhighlight>
    Primeiro, é claro, na linha 1 nós temos que incluir o arquivo de cabeçalho contendo a declaração da classe.
    Primeiro, é claro, na linha 1 nós temos que incluir o arquivo de cabeçalho contendo a declaração da classe.


    Line 69: Line 69:


    ==De volta ao main.cpp==
    ==De volta ao main.cpp==
    In order to actually run this window, we need to add a few lines in main.cpp:
    No intuito de executar atualmente esta janela, nós adicionamos umas poucas linhas no main.cpp
    ===main.cpp===
    ===main.cpp===
    <code cppqt n>
    <syntaxhighlight lang="cpp-qt" line>
    #include <KApplication>
    #include <KApplication>
    #include <KAboutData>
    #include <KAboutData>
    Line 94: Line 94:
       return app.exec();
       return app.exec();
    }
    }
    </code>
    </syntaxhighlight>
    As únicas linhas novas aqui (comparadas com o Tutorial 1) são 5, 18 e 19. Na linha 18, nós criamos o nosso objeto MainWindow e então, na linha 19, nós a exibimos.
    As únicas linhas novas aqui (comparadas com o Tutorial 1) são 5, 18 e 19. Na linha 18, nós criamos o nosso objeto MainWindow e então, na linha 19, nós a exibimos.


    Line 100: Line 100:
    The best way to build the program is to use CMake. All that's changed since tutorial 1 is that <tt>mainwindow.cpp</tt> has been added to the sources list and any <tt>tutorial1</tt> has become <tt>tutorial2</tt>.
    The best way to build the program is to use CMake. All that's changed since tutorial 1 is that <tt>mainwindow.cpp</tt> has been added to the sources list and any <tt>tutorial1</tt> has become <tt>tutorial2</tt>.
    ===CMakeLists.txt===
    ===CMakeLists.txt===
    <code ini n>
    <syntaxhighlight lang="ini" line>
    project (tutorial2)
    project (tutorial2)


    Line 113: Line 113:
    kde4_add_executable(tutorial2 ${tutorial2_SRCS})
    kde4_add_executable(tutorial2 ${tutorial2_SRCS})
    target_link_libraries(tutorial2 ${KDE4_KDEUI_LIBS})
    target_link_libraries(tutorial2 ${KDE4_KDEUI_LIBS})
    </code>
    </syntaxhighlight>


    ===Compile it===
    ===Compile isto===
    To compile, link and run it, use:
    Para compilar, crias as ligações e rodar, use:
      mkdir build && cd build
      mkdir build && cd build
      cmake ..
      cmake ..
    Line 122: Line 122:
      ./tutorial2
      ./tutorial2


    ==Moving On==
    ==Siga em frente==
    Now you can move on to [[Development/Tutorials/Using_KActions|using KActions]].
    Agora você pode ir ao tutorial [[Development/Tutorials/Using_KActions_(pt_BR)|usando KActions]].


    [[Category:C++]]
    [[Category:C++]]

    Latest revision as of 16:50, 15 July 2012

    Como usar o KXmlGuiWindow
    Série de Tutoriais   Tutorial para iniciantes
    Pré-requisitos   Tutorial 1 - Alô Mundo
    Qual é o próximo   Tutorial 3 - KActions e XMLGUI
    Leitura adicional   KXmlGuiWindow

    Resumo

    Este tutorial dá continuidade ao First Program Tutorial e introduzirá a classe KXmlGuiWindow.

    No tutorial anterior, o programa criava uma caixa de diálogo pop up, mas nós agora iremos andar alguns passos em direção ao funcionamento de uma aplicação.

    KXmlGuiWindow

    KXmlGuiWindow fornece a visão de uma janela principal inteira com barra de menus, barra de ferramentas, uma barra de status e uma área no centro para um widget grande. Muitas aplicações KDE derivam desta classe já que ela fornece um jeito fácil de definir o layout do menu e barra de ferramentas através de arquivos XML (esta tecnologia é chamada de XMLGUI). Por enquanto não usaremos o XMLGUI neste tutorial, mas nós o usaremos no próximo.

    In order to have a useful KXmlGuiWindow, we must subclass it. So we create two files, a mainwindow.cpp and a mainwindow.h which will contain our code.

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <KXmlGuiWindow>
    #include <KTextEdit>
    
    class MainWindow : public KXmlGuiWindow
    {
      public:
        MainWindow(QWidget *parent=0);
    		
      private:
        KTextEdit* textArea;
    };
    
    #endif
    

    First we Subclass KXmlGuiWindow on line 7 with class MainWindow : public KXmlGuiWindow.

    Então nós declaramos o construtor com MainWindow(QWidget *parent=0);.

    And finally we declare a pointer to the object that will make up the bulk of our program. KTextEdit is a generic richtext editor with some KDE niceties like cursor auto-hiding.

    mainwindow.cpp

    #include "mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent)
    {
      textArea = new KTextEdit();
      setCentralWidget(textArea);
      setupGUI();
    }
    

    Primeiro, é claro, na linha 1 nós temos que incluir o arquivo de cabeçalho contendo a declaração da classe.

    Na linha 5, nós iniciamos nosso editor de texto com um objeto. Então na linha 6 nós usamos a função setCentralWidget() do KXmlGuiWindow a qual chama o KXmlGuiWindow que deverá aparecer na parte central da janela.

    Finalmente, KXmlGuiWindow::setupGUI() é chamado, a qual faz várias coisas por-trás-dos-bastidores e cria a barra de menu padrão (Configurações, Ajuda).

    De volta ao main.cpp

    No intuito de executar atualmente esta janela, nós adicionamos umas poucas linhas no main.cpp

    main.cpp

    #include <KApplication>
    #include <KAboutData>
    #include <KCmdLineArgs>
    
    #include "mainwindow.h"
    
    int main (int argc, char *argv[])
    {
      KAboutData aboutData( "tutorial2", 0,
          ki18n("Tutorial 2"), "1.0",
          ki18n("A simple text area"),
          KAboutData::License_GPL,
          ki18n("Copyright (c) 2007 Developer") );
      KCmdLineArgs::init( argc, argv, &aboutData );
      
      KApplication app;
     
      MainWindow* window = new MainWindow();
      window->show();
    
      return app.exec();
    }
    

    As únicas linhas novas aqui (comparadas com o Tutorial 1) são 5, 18 e 19. Na linha 18, nós criamos o nosso objeto MainWindow e então, na linha 19, nós a exibimos.

    CMake

    The best way to build the program is to use CMake. All that's changed since tutorial 1 is that mainwindow.cpp has been added to the sources list and any tutorial1 has become tutorial2.

    CMakeLists.txt

    project (tutorial2)
    
    find_package(KDE4 REQUIRED)
    include_directories(${KDE4_INCLUDES})
    
    set(tutorial2_SRCS 
      main.cpp
      mainwindow.cpp
    )
    
    kde4_add_executable(tutorial2 ${tutorial2_SRCS})
    target_link_libraries(tutorial2 ${KDE4_KDEUI_LIBS})
    

    Compile isto

    Para compilar, crias as ligações e rodar, use:

    mkdir build && cd build
    cmake ..
    make
    ./tutorial2
    

    Siga em frente

    Agora você pode ir ao tutorial usando KActions.